EDIT – so the above happened and maybe there is a complete post on its own here to reflect on the news I woke up to this morning, but I am not as shocked as I thought I would be. Having spoken throughout my night to a lot of my American friends who seem fine not overjoyed with the prospect but not running for the border of Canada, that might change when they have a nights sleep.
Let’s get back on track, Automation within my home lab. Over the last few years in general and work surroundings I have found myself trying to make my life easier, back when I was installing and provisioning NetApp and VMware environments I would look at ways how I could automate the provisioning of volumes, LUNs and then presenting them to vSphere. Simple scripts just created in NotePad ++ if you have not used this free tool then you should be it adds so much ease for just boringly long tasks.
I will use PowerShell to achieve some basic automation tasks and I’ll share my setup and scripts in this post, but please note that this is (as always) work in progress and is by no means a perfect solution. PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. The reason for choosing PowerShell is simple, from a vSphere point of view we have the ability of leveraging PowerShell through PowerCLI and also through Veeam we can use aspects of PowerShell.
I have never really got involved from a “coding” point of view if you can even call that, I know the scripts below are not deemed a coding exercise as such and I am not going to start getting all DevOps on you.
Shutdown VMs
#All virtual machine IP addresses should be included here.
Restart-Computer -Computer localhost -Force -Credential michael.cade@outlook.com
Stop-Computer -Computer 192.168.2.16,192.168.2.17, 192.168.2.18 -Force -Credential Administrator@vzilla.co.uk
#Connect to VC which is hosted on MSI (MGMT) and then Nested ESXi Hosts are shut down.
Connect-VIServer -server 192.168.2.11 -Protocol https -User Administrator@vzilla.co.uk
Stop-VMhost 192.168.2.125,192.168.2.126,192.168.2.127,192.168.2.128 -Confirm -Force
#The command below will shut down all physical ESXi hosts
Stop-VMhost 192.168.2.121,192.168.2.122,192.168.2.123 -Confirm -Force
Restart-Computer localhost
#This command will shut down the Management nested ESXi host on the MSI
Stop-Computer -Computer 192.168.2.10 -Force -Credential Administrator@vZilla.co.uk
Get-VM
Stop-VM -VM dc01 -Confirm
Stop-VMhost 192.168.2.124 -Confirm -Force
Stop-VM NetApp_AltaVault01 -confirm
#Connect to VC which is hosted on MSI (MGMT) and then Nested ESXi Hosts are shut down.
Connect-VIServer -server 192.168.2.11 -Protocol https -User Administrator@vzilla.co.uk
Get-VM
#Start NetApp AltaVault Appliance
Start-VM NetApp_AltaVault01 -confirm
#Can we be used to pause commands
Start-Sleep -Seconds 60
Get-VM
#Start Veeam servers
Start-VM Veeam_BR01,Veeam_ONE -confirm
#Start Nested ESXi hosts – takes 5 minutes for this to complete.
Start-VM ESX01,ESX02,ESX03,ESX04 -Confirm
#Start Exchange VM
Start-VM Exch01 -confirm
#Start SQL VM
Start-VM SQL01 -confirm
#Start Oracle VM
Start-VM Ora01 -confirm
#Start Sharepoint VM
Start-VM SP01 -confirm
Firewall & Access
#allowing remote access to machine
Set-Item wsman:\localhost\Client\TrustedHosts -value *
Set-Item wsman:\localhost\Client\TrustedHosts 192.168.2.10 -Concatenate -Force
Set-Item wsman:\localhost\Client\TrustedHosts DC01 -Concatenate -Force
Set-Item wsman:\localhost\Client\TrustedHosts DC01.vzilla.co.uk -Concatenate -Force
Set-NetFirewallProfile -Profile * -Enabled False
Invoke-Command -ComputerName 192.168.2.18 -Credential Administrator@vzilla.co.uk -FilePath C:\Users\Michael\Desktop\NoFirewall.ps1
#Enable Remote Desktop
Set-ItemProperty -Path ‘HKLM:\system\CurrentControlSet\Control\Terminal Server’-name “fDenyTSConnections”-value 0
Enable-NetFirewallRule -DisplayGroup “Remote Desktop”
Set-itemProperty -Path ‘HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp’-name “UserAuthentication”-Value 1
Thanks for reading, the next post in the series is going to cover off more about automation but now touching on the vSphere tags and how I have created a simple approach and profiling system within the lab.