Hyper-V Commands

Microsoft Hyper-V PowerShell cmdlets for hypervisor management.

Host Startup Procedure

Step 1: Power on physical host

Boot the Hyper-V server hardware

Step 2: Wait for host boot

Wait for Windows Server to fully boot (3-5 minutes)

Get-Service vmms

Check Hyper-V Virtual Machine Management service status

Start-Service vmms

Start Hyper-V service if not running

Get-VM

List all VMs and their states

Step 3: Start VMs with auto-start

VMs configured with automatic start will boot automatically

Get-VM | Where-Object {$_.State -eq "Off" -and $_.AutomaticStartAction -ne "Nothing"}

List VMs configured for auto-start

Step 4: Manually start remaining VMs

Start VMs that require manual intervention

VM Management

Get-VM

List all virtual machines

Get-VM -Name <VMName>

Get specific VM details

New-VM -Name <VMName> -MemoryStartupBytes <Bytes> -Generation 2

Create new Generation 2 VM

Start-VM -Name <VMName>

Start a VM

Stop-VM -Name <VMName>

Gracefully shutdown VM

Stop-VM -Name <VMName> -TurnOff

Force power off VM

Restart-VM -Name <VMName>

Restart VM

Suspend-VM -Name <VMName>

Pause VM

Resume-VM -Name <VMName>

Resume paused VM

Save-VM -Name <VMName>

Save VM state

Remove-VM -Name <VMName>

Delete VM (keeps VHD files)

Remove-VM -Name <VMName> -Force

Force delete VM without confirmation

Set-VM -Name <VMName> -ProcessorCount <Count>

Set CPU count

Set-VM -Name <VMName> -MemoryStartupBytes <Bytes>

Set startup memory

Set-VM -Name <VMName> -DynamicMemory

Enable dynamic memory

Set-VM -Name <VMName> -AutomaticStartAction Start

Enable automatic start

Set-VM -Name <VMName> -AutomaticStopAction ShutDown

Set shutdown action on host stop

Virtual Disk Management

Get-VHD -Path <Path>

Display VHD/VHDX information

New-VHD -Path <Path> -SizeBytes <Bytes> -Dynamic

Create dynamic VHD

New-VHD -Path <Path> -SizeBytes <Bytes> -Fixed

Create fixed VHD

Resize-VHD -Path <Path> -SizeBytes <Bytes>

Resize VHD

Convert-VHD -Path <Source> -DestinationPath <Dest>

Convert VHD format

Test-VHD -Path <Path>

Verify VHD integrity

Optimize-VHD -Path <Path> -Mode Full

Compact VHD

Add-VMHardDiskDrive -VMName <VMName> -Path <Path>

Attach VHD to VM

Remove-VMHardDiskDrive -VMName <VMName> -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 1

Remove disk from VM

Get-VMHardDiskDrive -VMName <VMName>

List VM disks

Network Management

Get-VMSwitch

List all virtual switches

New-VMSwitch -Name <Name> -NetAdapterName <Adapter> -AllowManagementOS $true

Create external vSwitch with management access

New-VMSwitch -Name <Name> -SwitchType Internal

Create internal vSwitch

New-VMSwitch -Name <Name> -SwitchType Private

Create private vSwitch

Remove-VMSwitch -Name <Name>

Delete virtual switch

Get-VMNetworkAdapter -VMName <VMName>

List VM network adapters

Add-VMNetworkAdapter -VMName <VMName> -SwitchName <Switch>

Add network adapter to VM

Remove-VMNetworkAdapter -VMName <VMName> -Name <AdapterName>

Remove network adapter

Set-VMNetworkAdapter -VMName <VMName> -StaticMacAddress <MAC>

Set static MAC address

Set-VMNetworkAdapterVlan -VMName <VMName> -Access -VlanId <ID>

Set VLAN for adapter

Get-VMNetworkAdapterVlan -VMName <VMName>

Display VLAN configuration

Checkpoint Management

Get-VMCheckpoint -VMName <VMName>

List VM checkpoints

Checkpoint-VM -Name <VMName> -SnapshotName <Name>

Create checkpoint

Restore-VMCheckpoint -VMName <VMName> -Name <Checkpoint>

Restore checkpoint

Remove-VMCheckpoint -VMName <VMName> -Name <Checkpoint>

Delete checkpoint

Export-VMCheckpoint -VMName <VMName> -Name <Checkpoint> -Path <Path>

Export checkpoint

Set-VM -Name <VMName> -CheckpointType Production

Enable production checkpoints

Set-VM -Name <VMName> -CheckpointType Standard

Enable standard checkpoints

Replication & Backup

Enable-VMReplication -VMName <VMName> -ReplicaServerName <Server> -AuthenticationType Kerberos

Enable VM replication

Start-VMInitialReplication -VMName <VMName>

Start initial replication

Get-VMReplication -VMName <VMName>

Display replication status

Start-VMFailover -VMName <VMName> -Prepare

Prepare for planned failover

Start-VMFailover -VMName <VMName>

Perform failover

Export-VM -Name <VMName> -Path <Path>

Export VM

Import-VM -Path <Path>

Import VM

Compare-VM -Path <Path>

Validate VM for import

Host Configuration

Get-VMHost

Display Hyper-V host information

Set-VMHost -VirtualHardDiskPath <Path>

Set default VHD path

Set-VMHost -VirtualMachinePath <Path>

Set default VM path

Get-VMHostNumaNode

Display NUMA topology

Get-VMHostSupportedVersion

List supported VM versions

Enable-VMResourceMetering -VMName <VMName>

Enable resource metering

Measure-VM -VMName <VMName>

Display resource usage metrics

Test-VmNetworkAdapter -VMName <VMName> -Sender

Test network adapter connectivity

Cluster Management

Get-ClusterNode

List cluster nodes

Get-ClusterResource

List cluster resources

Get-ClusterGroup

List cluster groups

Move-ClusterVirtualMachineRole -Name <VMName> -Node <Node>

Live migrate VM to another node

Add-ClusterVirtualMachineRole -VirtualMachine <VMName>

Make VM highly available

Get-ClusterSharedVolume

List cluster shared volumes

Test-Cluster

Run cluster validation tests

Monitoring & Troubleshooting

Get-VM | Select Name, State, CPUUsage, MemoryAssigned

Display VM resource usage

Get-VMMemory -VMName <VMName>

Display VM memory configuration

Get-VMProcessor -VMName <VMName>

Display VM processor configuration

Get-VMIntegrationService -VMName <VMName>

Display integration services status

Enable-VMIntegrationService -VMName <VMName> -Name <Service>

Enable integration service

Get-VMReplicationHealth -VMName <VMName>

Check replication health

Get-VMResourcePool

List resource pools

Get-Counter -Counter "Hyper-V Hypervisor Logical Processor(*)% Total Run Time"

Monitor hypervisor CPU usage

Get-EventLog -LogName "Microsoft-Windows-Hyper-V-VMMS-Admin" -Newest 50

View Hyper-V event logs