VMware Cloud Community
pamiller21
Enthusiast
Enthusiast

Shutdown and Start up script

I would like to find a way to power down all VMs that are powered up in a cluster for a big maintenance window. I would also like to have the whatif option to test before hand if possible.

Then I would like to have a CSV list to boot up the VMs after the window and also have a what if option as well.

Thank you in advance!

0 Kudos
1 Reply
LucD
Leadership
Leadership

Try something like this.

Change the $whatif variable to $false if you want to actually stop the running VMs.

Same for the starting part.

$whatif = $true

$clusterName = 'Cluster1'

$fileName = 'C:\Temp\VMnames.csv'

# Stopping

$vms = Get-Cluster -Name $clusterName | Get-VM | where{$_.PowerState -eq 'PoweredOn'}

$vms | Shutdown-VMGuest -Confirm:$false -WhatIf:$whatif

$vms | select Name | Export-Csv -Path $fileName -NoTypeInformation -UseCulture

# Starting

$vms = Import-Csv -Path $fileName -UseCulture

Get-VM -Name $vms.Name | Start-VM -WhatIf:$whatif

 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos