VMware Cloud Community
pkDMV
Contributor
Contributor

Need help with Gracefully shutdown and power up VMs in a cluster script

If I want to make a graceful shutdown and power-On script, would this script from LucD work?

# Get all powered on VMs in hash table and shutdown vm

Function Get-Devshutdown{

$vmTab = @{}

Get-Folder powershell | Get-Cluster Development | Get-VM | where {$_.PowerState -eq "PoweredOn"} | %{

   $vmTab.Add($_.Name,$_)}

$vmTab.Values | %{

   $vm = Get-VM -Name $_.VM.Name

   Stop-VM -VM $vm -Confirm:$false

}

}

Function Get-Devpowerup{

$vmTab.Values | %{

   $vm = Get-VM -Name $_.VM.Name

   Start-VM -VM $vm -Confirm:$false

}

}

0 Kudos
1 Reply
LucD
Leadership
Leadership

No, that is not a graceful shutdown.
The Stop-VM is like pushing the power switch.

For a graceful shutdown you need the Stop-VMGuest cmdlet.
But note that this requires VMware Tools to be installed.


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

0 Kudos