Day 9 – Post 9, I wrote this prior to knowing the outcome of the US presidential vote…. I stand by if Donald Trump at the time of publishing this is President then we are going to be in a world of pain as a world not just the US!

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.

So I wanted to include some level of automation in the home lab, or maybe not a want but a must as the reason for my use of automation is to ultimately save my house money as well as an organised chaos of bringing up certain lab requirements.

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.

I wanted to share some of the scripts I have used and prepared within my home lab, running through the PowerShell Integrated Scripting Environment (ISE) pretty much always open on my admin machine and allows to tweak the configurable to suit my requirement.

Shutdown VMs

#This script is designed to shut down the Virtual Machines, Nested ESXi and Physical Machines

#All virtual machine IP addresses should be included here.

Restart-Computer -Computer localhost -Force -Credential
Stop-Computer -Computer,, -Force -Credential

#Connect to VC which is hosted on MSI (MGMT) and then Nested ESXi Hosts are shut down.

Connect-VIServer -server -Protocol https -User
Stop-VMhost,,, -Confirm -Force

#The command below will shut down all physical ESXi hosts
Stop-VMhost,, -Confirm -Force

Restart-Computer localhost

#This command will shut down the Management nested ESXi host on the MSI
Stop-Computer -Computer -Force -Credential
Stop-VM -VM dc01 -Confirm
Stop-VMhost -Confirm -Force

Stop-VM NetApp_AltaVault01 -confirm

Start up

#This report will allow for specific virtual machines to be started, this script will contain all scripts not all should be run at the same time.

#Connect to VC which is hosted on MSI (MGMT) and then Nested ESXi Hosts are shut down.
Connect-VIServer -server -Protocol https -User

#Start NetApp AltaVault Appliance
Start-VM NetApp_AltaVault01 -confirm

#Can we be used to pause commands
Start-Sleep -Seconds    60

#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 -Concatenate -Force
Set-Item wsman:\localhost\Client\TrustedHosts DC01 -Concatenate -Force
Set-Item wsman:\localhost\Client\TrustedHosts -Concatenate -Force
Set-NetFirewallProfile -Profile * -Enabled False
Invoke-Command -ComputerName -Credential -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.

Leave a Reply

Your email address will not be published. Required fields are marked *