Created
April 29, 2022 14:03
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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