Skip to content

Instantly share code, notes, and snippets.

@alfredmyers
Last active September 8, 2019 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfredmyers/dfa9c6ee466cbe505a6a2e31013b2ef5 to your computer and use it in GitHub Desktop.
Save alfredmyers/dfa9c6ee466cbe505a6a2e31013b2ef5 to your computer and use it in GitHub Desktop.
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 }
Param(
$VMName,
$MemoryStartupBytes,
$NewVHDSizeBytes,
$IsoPath
)
$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
Param(
$VMName
)
$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