Hi Community Members,
I have been working with variations of scripts that will allow you to gracefully shutdown our Virtual Environment. Since we have many Infrastructure machines running as VM's,( i.e, Domain Controllers, DHCP Servers, VCenter Servers), we wanted to be able to shutdown the machines in the appropriate order based on a Tiered Structure.
We currently have a great script, (thanks to resources within this community), that identifies all of the machines that are powered on, exports that information and works with a second script to power up only the machines that we previously powered down. The trouble is we have to name each machine that we want to, (or dont want to shut down). the line in the script looks like this:
#Get-VM -Location $cluster | Where-Object { $_.PowerState -eq “PoweredOn” } | where { $_.Name -notlike “*DB*” -and $_.Name -notlike “*VC*” -and $_.Name -notlike “*DC*” }
A colleague thought that it would be a great idea to add a custom attribute, then have the shutdown script look for that specific attribute and Shutdown/Suspend that machine.
So we created an annotation for all machines, lets call it "SD_Procedure" and give it a value of 1, 2, or 3 based on the order that want the machines to shut down, (tier 3 shutdown first, then Tier 2 then Tier 1, etc.). I can pull these machines with the following line:
#Get-VM | get-annotation -Name SD_Proedure | where-object {$_.Value -eq "2"}
My trouble is that I want to identify the machines that are currently powered on as well as the ones that with a specific Value in the annotation field, and shut that machine down. I cant figure how these should be combined to get the correct result.
Can someone help?