Powershell
Shutdown all running guests in VMware
## ===================================================================== ## Title : Shutdown running VM's ## Description : Script to shutdown all runnning guests in a virtual infrastructure ## Author : Marco Baars ## January 2010 ## ===================================================================== add-pssnapin VMware.VimAutomation.Core # Connect to Virtual Center server $VIserver = "viserver" Connect-VIServer $VIserver # Run trough all guests $VMarray = Get-VM cls foreach ($item in $VMarray) { if ($Item.Powerstate -eq "Poweredon") { $ServerName = $Item.Name "Server " + $ServerName + " is powered on" "Shutting down " + $ServerName # The VMware way (simulates power button) # Get-VM $Item.Name | Shutdown-VMGuest -Confirm # This one suspends the virtual machine # Get-VM $Item.Name | Suspend-VMGuest # Shutdown the Windows way via WMI $win32OS = get-wmiobject win32_operatingsystem -computername $ServerName $win32OS.psbase.Scope.Options.EnablePrivileges = $true $win32OS.win32shutdown(1) } }
Last Updated (Monday, 18 January 2010 16:30)