Created
August 30, 2023 03:55
-
-
Save keithga/4afac6a8ebfa91512b7f33350c9ee0ca to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# This script will remove the VM *AND* Vhd | |
$VMs = get-vm | Out-GridView -OutputMode Multiple | |
$Disks = $VMs | Get-VMHardDiskDrive | % path | |
$VMs | stop-vm -Force -TurnOff -Confirm:$False -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | |
$VMs | Remove-VM -Force -Confirm:$False | |
$disks | Write-Verbose | |
while ( test-path $Disks ) { | |
try { | |
remove-item $Disks -Force | |
} | |
catch { | |
write-host "Retry Deletion..." | |
start-sleep 10 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment