Skip to content

Instantly share code, notes, and snippets.

@jonchampagne
Created April 29, 2022 14:03
Show Gist options
  • Save jonchampagne/542f95ee738be0bb9f19821d6221b7b7 to your computer and use it in GitHub Desktop.
Save jonchampagne/542f95ee738be0bb9f19821d6221b7b7 to your computer and use it in GitHub Desktop.
PowerCLI: Shut down a virtual machine, and wait for it to be fully shut down.
function Stop-VMGuestAndWait {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)][String]$VMName
)
Stop-VMGuest $VMName -Confirm:$false
do {
Start-Sleep -Seconds 1
$VMStatus = (Get-VM $VMName).PowerState
} while ($VMStatus -ne "PoweredOff")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment