Skip to content

Instantly share code, notes, and snippets.

Last active Sep 8, 2019
What would you like to do?
Power-V: PowerShell scripts for managing Hyper-V virtual machines
Get-VM | Remove-VMSnapshot
$rootedVHDs = (Get-VM).HardDrives.Path
Return Get-ChildItem (Get-VMHost).VirtualHardDiskPath | Where-Object { $_.FullName -notin $rootedVHDs }
$VM = New-VM $VMName $MemoryStartupBytes 2 -NewVHDPath ($VMName + ".vhdx") -NewVHDSizeBytes $NewVHDSizeBytes -BootDevice VHD -SwitchName External
Set-VM $VM -ProcessorCount 2 -MemoryMaximumBytes $MemoryStartupBytes -AutomaticCheckpointsEnabled $false
Set-VMFirmware $VM -EnableSecureBoot Off
Add-VMDvdDrive $VM -Path $IsoPath
Return $VM
$vm = Get-VM $VMName
Get-VMSnapshot $vm | Remove-VMSnapshot
$vhds = $vm.HardDrives.Path
Remove-VM $vm -Force
Remove-Item $vhds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment