Last active
September 8, 2019 22:55
-
-
Save alfredmyers/dfa9c6ee466cbe505a6a2e31013b2ef5 to your computer and use it in GitHub Desktop.
Power-V: PowerShell scripts for managing Hyper-V virtual machines
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
Get-VM | Remove-VMSnapshot | |
$rootedVHDs = (Get-VM).HardDrives.Path | |
Return Get-ChildItem (Get-VMHost).VirtualHardDiskPath | Where-Object { $_.FullName -notin $rootedVHDs } |
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
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 |
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
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