ops@toolbox:~$ Get-Command -Module Hyper-V

Hyper-V Reference

Windows PowerShell Hyper-V module cmdlets: VM management, checkpoints, virtual switches, VHD/VHDX and live migration. Searchable and copy-ready.

Run in an elevated PowerShell session on the Hyper-V host, or add -ComputerName HV01 for remote management. Enable WinRM first: Enable-PSRemoting -Force

πŸ“‹ VM Inventory

Get-VMList all VMs on this host
Get-VM | Select Name, State, Generation, @{N='MemMB';E={[int]($_.MemoryAssigned/1MB)}}, ProcessorCount | Sort NameVM summary, state, generation, memory, CPU
Get-VM -ComputerName HV01List VMs on a remote Hyper-V host
Get-VM | Where-Object {$_.State -eq 'Off'}Find all stopped VMs
(Get-VM).CountTotal VM count on this host
Get-VM | Group-Object State | Select Name, CountVM count by power state

⚑ Power Operations

Start-VM -Name "MyVM"Power on VM
Stop-VM -Name "MyVM"Guest OS shutdown (requires Integration Services)
Stop-VM -Name "MyVM" -TurnOffHard power off (like pulling the plug)
Restart-VM -Name "MyVM" -ForceHard reset VM
Suspend-VM -Name "MyVM"Save state (hibernate) VM to disk
Resume-VM -Name "MyVM"Resume VM from saved state
Get-VM | Start-VMStart ALL VMs on this host

πŸ†• Create & Configure

New-VM -Name "NewVM" -Generation 2 -MemoryStartupBytes 4GB -SwitchName "Default Switch" -NewVHDPath "C:\VMs\NewVM.vhdx" -NewVHDSizeBytes 60GBCreate a Gen 2 VM with a new VHDX
Set-VM -Name "MyVM" -ProcessorCount 4 -MemoryStartupBytes 8GB -AutomaticStartAction StartChange CPU, RAM and auto-start behaviour
Set-VM -Name "MyVM" -DynamicMemory -MemoryMinimumBytes 1GB -MemoryMaximumBytes 16GBEnable Dynamic Memory with min/max bounds
Remove-VM -Name "MyVM" -ForceDelete VM registration (does NOT delete VHDX files)

πŸ“Έ Checkpoints (Snapshots)

Checkpoint-VM -Name "MyVM" -SnapshotName "Pre-Patch-$(Get-Date -f yyyy-MM-dd)"Create checkpoint with date-stamped name
Get-VMCheckpoint -VMName "MyVM"List all checkpoints for a VM
Get-VM | Get-VMCheckpoint | Select VMName, Name, CreationTime | Sort VMNameAll checkpoints across all VMs
Restore-VMCheckpoint -Name "Pre-Patch" -VMName "MyVM" -Confirm:$falseRevert VM to a checkpoint (VM must be off)
Remove-VMCheckpoint -VMName "MyVM" -Name "Pre-Patch"Delete a checkpoint (merges delta into parent)
Get-VM | Get-VMCheckpoint | Where-Object {$_.CreationTime -lt (Get-Date).AddDays(-14)} | Remove-VMCheckpointRemove checkpoints older than 14 days
Export-VM -Name "MyVM" -Path "D:\Exports"Export VM to folder (backup or migration)
Import-VM -Path "D:\Exports\MyVM\Virtual Machines\*.vmcx" -Copy -GenerateNewIdImport VM with a new unique ID

🌐 Virtual Networking

Get-VMSwitchList all virtual switches
New-VMSwitch -Name "ExternalSwitch" -NetAdapterName "Ethernet" -AllowManagementOS $trueCreate external switch (bridged to physical NIC)
New-VMSwitch -Name "InternalSwitch" -SwitchType InternalCreate internal switch (host + VMs can communicate)
New-VMSwitch -Name "PrivateSwitch" -SwitchType PrivateCreate private switch (VM-to-VM only, no host)
Get-VMNetworkAdapter -VMName "MyVM"List VM network adapters and MAC addresses
Add-VMNetworkAdapter -VMName "MyVM" -SwitchName "ExternalSwitch"Add a NIC to a VM
Set-VMNetworkAdapterVlan -VMName "MyVM" -VMNetworkAdapterName "Network Adapter" -Access -VlanId 20Set VLAN ID on a VM NIC (access mode)

πŸ’Ύ VHD / VHDX Storage

New-VHD -Path "C:\VMs\disk.vhdx" -SizeBytes 100GB -DynamicCreate a new dynamic VHDX (grows on demand)
New-VHD -Path "C:\VMs\disk.vhdx" -SizeBytes 100GB -FixedCreate fixed-size VHDX (better I/O performance)
Get-VHD -Path "C:\VMs\disk.vhdx" | Select Path, VhdType, Size, FileSizeInspect a VHD/VHDX file
Resize-VHD -Path "C:\VMs\disk.vhdx" -SizeBytes 200GBExpand VHDX, extend the guest OS partition separately
Optimize-VHD -Path "C:\VMs\disk.vhdx" -Mode FullCompact VHDX to reclaim space (VM must be off)
Convert-VHD -Path "C:\VMs\disk.vhd" -DestinationPath "C:\VMs\disk.vhdx" -VHDType DynamicConvert legacy VHD to VHDX format
Get-VMHardDiskDrive -VMName "MyVM"List disks attached to a VM
Add-VMHardDiskDrive -VMName "MyVM" -Path "C:\VMs\data.vhdx"Attach an existing VHDX to a VM

πŸš€ Live Migration

Move-VM -Name "MyVM" -DestinationHost "HV02" -IncludeStorage -DestinationStoragePath "D:\VMs"Live migrate VM and storage to another host
Move-VM -Name "MyVM" -DestinationHost "HV02"Live migrate compute only (shared storage scenario)
Get-VMReplication -VMName "MyVM"Check Hyper-V Replica status
Get-VMReplication | Where-Object {$_.ReplicationHealth -ne "Normal"}Find VMs with replication issues

πŸ“Š Monitoring & Reporting

Measure-VM -Name "MyVM"CPU and memory metrics (enable metering first)
Enable-VMResourceMetering -VMName "MyVM"Enable resource metering for a VM
Get-VM | Select Name, @{N='CPU%';E={(Get-VM $_.Name).CPUUsage}}, @{N='MemMB';E={[int]($_.MemoryAssigned/1MB)}}Real-time CPU and memory for all VMs
Get-VMIntegrationService -VMName "MyVM" | Select Name, Enabled, PrimaryStatusDescriptionIntegration Services health check
Get-VM | Get-VMNetworkAdapter | Select VMName, MacAddress, IPAddressesVM IPs from Hyper-V (requires Integration Services)

Generation 1 vs Generation 2

Generation 2 VMs use UEFI firmware, support Secure Boot and PXE boot from virtual NICs, and generally perform better. Use Gen 2 for all new Windows Server 2012+ and modern Linux guests. You cannot change generation after VM creation, choose wisely upfront. Note that some older OSes (Windows XP, Server 2003, FreeBSD) require Gen 1.

Checkpoints vs Export for backup

Checkpoints are not backups; they consume additional disk space and degrade I/O performance as they grow. The safe approach: create a checkpoint before patching, verify the system works, then delete the checkpoint to merge it back. For actual backups use Export-VM to a separate drive, or a dedicated solution like Veeam, Altaro or Windows Server Backup.

Remote management

Add -ComputerName HV02 to most cmdlets for remote management. Ensure WinRM is enabled (Enable-PSRemoting -Force) and the account has Hyper-V Administrator rights. For non-domain environments, add the remote host to TrustedHosts: Set-Item WSMan:\localhost\Client\TrustedHosts -Value "HV02".

Related tools

VMware ESXi Reference
esxcli, PowerCLI and govc commands for vSphere.
Citrix Reference
CVAD PowerShell and Citrix ADC CLI commands.
Subnet Calculator
IPv4 CIDR with subnet split and find-prefix.