The Ultimate Hyper-V PowerShell Commands Cheat Sheet
PowerShell is a powerful scripting language that can be used to manage various aspects of Hyper-V, Microsoft’s virtualization platform. Below are some common Hyper-V tasks and the corresponding PowerShell code to perform them. Remember to run PowerShell with administrator privileges when managing Hyper-V, as some tasks may require elevated permissions.
List all virtual machines:
Get-VM
Start a virtual machine:
Start-VM -Name “YourVMName”
Stop a virtual machine:
Stop-VM -Name “YourVMName” -Force
Create a new virtual machine:
New-VM -Name “NewVM” -MemoryStartupBytes 2GB -NewVHDPath “C:\Path\to\YourVM.vhdx” -NewVHDSizeBytes 50GB
Set the amount of memory for a virtual machine:
Set-VMMemory -VMName “YourVMName” -DynamicMemoryEnabled $true -MinimumBytes 512MB -MaximumBytes 4GB
Attach a virtual DVD drive to a virtual machine:
Add-VMDvdDrive -VMName “YourVMName” -Path “C:\Path\to\YourISO.iso”
Get information about a virtual machine:
Get-VM “YourVMName” | Format-List *
Export a virtual machine:
Export-VM -Name “YourVMName” -Path “C:\Path\to\ExportFolder”
Import a virtual machine:
Import-VM -Path “C:\Path\to\ExportFolder” -Copy -GenerateNewId
Get a list of virtual switches:
Get-VMSwitch
List all virtual hard drives (VHDs):
Get-VHD
Create a new virtual hard drive:
New-VHD -Path “C:\Path\to\YourNewVHD.vhdx” -SizeBytes 100GB -Dynamic
Attach a virtual hard drive to a virtual machine:
Add-VMHardDiskDrive -VMName “YourVMName” -Path “C:\Path\to\YourExistingVHD.vhdx”
Remove a virtual hard drive from a virtual machine:
Remove-VMHardDiskDrive -VMName “YourVMName” -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 1
Snapshot a virtual machine:
Checkpoint-VM -VMName “YourVMName” -SnapshotName “YourSnapshotName”
Revert a virtual machine to a specific snapshot:
Restore-VMSnapshot -VMName “YourVMName” -Name “YourSnapshotName”
Export all virtual machines:
Get-VM | Export-VM -Path “C:\Path\to\ExportAllVMs” -NamePrefix “Exported”
Get information about virtual machine network adapters:
Get-VMNetworkAdapter -VMName “YourVMName”
Change the number of virtual processors for a virtual machine:
Set-VMProcessor -VMName “YourVMName” -Count 4
Enable Nested Virtualization for a virtual machine:
Set-VMProcessor -VMName “YourVMName” -ExposeVirtualizationExtensions $true
Get information about running virtual machines:
Get-VM | Where-Object { $_.State -eq ‘Running’ }
Get a list of all checkpoints (snapshots) for a virtual machine:
Get-VMSnapshot -VMName “YourVMName”
Remove a checkpoint (snapshot) for a virtual machine:
Remove-VMSnapshot -VMName “YourVMName” -Name “YourSnapshotName”
Rename a virtual machine:
Rename-VM -VMName “OldVMName” -NewName “NewVMName”
Change the boot order of a virtual machine:
Set-VMFirmware -VMName “YourVMName” -FirstBootDevice “CD”
Enable or disable Hyper-V Integration Services:
Get-VMIntegrationService -VMName “YourVMName” | Enable-VMIntegrationService -Name “GuestServiceInterface”
Get-VMIntegrationService -VMName “YourVMName” | Disable-VMIntegrationService -Name “GuestServiceInterface”
List all Hyper-V checkpoints on the host:
Get-VMSnapshot -ComputerName “YourHyperVHost”
Create a new Hyper-V virtual switch:
New-VMSwitch -Name “YourSwitchName” -SwitchType External -NetAdapterName “YourPhysicalNIC”
Set up a virtual machine to start automatically with the host:
Set-VM -VMName “YourVMName” -AutomaticStartAction Start -AutomaticStartDelay 120
Configure Hyper-V replication for a virtual machine:
Enable-VMReplication -VMName “YourVMName” -ReplicaServerName “TargetHyperVHost” -ReplicaServerPortNumber 80 -AuthenticationType Kerberos
Display Hyper-V host information:
Get-VMHost
Set CPU weight for a virtual machine:
Set-VMProcessor -VMName “YourVMName” -RelativeWeight 200
Check the status of Hyper-V replication:
Get-VMReplication -VMName “YourVMName”
Start Hyper-V replication for a virtual machine:
Start-VMReplication -VMName “YourVMName” -ReplicaServerName “TargetHyperVHost” -ReplicaServerPortNumber 80 -AuthenticationType Kerberos
Stop Hyper-V replication for a virtual machine:
Stop-VMReplication -VMName “YourVMName” -ReplicaServerName “TargetHyperVHost”
Configure Hyper-V Replica frequency:
Set-VMReplication -VMName “YourVMName” -ReplicationFrequencyInSec 300
Check Hyper-V virtual machine integration services status:
Get-VMIntegrationService -VMName “YourVMName”
Configure Hyper-V virtual machine automatic checkpoints:
Set-VM -VMName “YourVMName” -CheckpointType Standard -CheckpointFileLocation “C:\Path\to\Checkpoints”
Set up Hyper-V dynamic memory for a virtual machine:
Set-VMMemory -VMName “YourVMName” -DynamicMemoryEnabled $true -MinimumBytes 512MB -MaximumBytes 8GB
Export Hyper-V virtual machine configuration settings:
Export-VM -Name “YourVMName” -ConfigurationOnly -Path “C:\Path\to\ConfigurationExport”
Clone a virtual machine:
New-VM -Name “ClonedVM” -VMPath “C:\Path\to\ClonedVM” -Generation 2 -Copy -ReferenceSnapshotName “YourSnapshotName”
Assign a static MAC address to a virtual network adapter:
Get-VMNetworkAdapter -VMName “YourVMName” | Set-VMNetworkAdapter -StaticMacAddress “00:15:5D:00:01:23”
Configure Hyper-V host networking settings:
Get-NetAdapter | Where-Object { $_.InterfaceDescription -eq “Microsoft Hyper-V Network Adapter” } | Set-NetIPInterface -DHCP Disabled
Enable Nested Virtualization at the host level:
Set-VMHost -EnableEnhancedSessionMode $true
View Hyper-V virtual machine events:
Get-WinEvent -LogName Microsoft-Windows-Hyper-V-VMMS-Admin
Change the startup memory for a virtual machine:
Set-VMMemory -VMName “YourVMName” -StartupBytes 2GB
List all Hyper-V checkpoints on a virtual machine:
Get-VMSnapshot -VMName “YourVMName” | Select-Object VMName, Name, CreationTime
Enable Hyper-V replication compression:
Set-VMReplication -VMName “YourVMName” -ReplicationEnableCompression $true
View Hyper-V host processor information:
Get-Processor | Format-List *
Configure Hyper-V Smart Paging file location:
Set-VM -VMName “YourVMName” -SmartPagingFilePath “C:\Path\to\SmartPagingFile”
Configure Hyper-V host for Live Migration:
Enable-VMMigration -MaxReceiveInterval 500 -AuthenticationType CredSSP
Set up Hyper-V replication for multiple virtual machines:
Get-VM -Name “VM1”, “VM2” | Enable-VMReplication -ReplicaServerName “TargetHyperVHost” -ReplicaServerPortNumber 80 -AuthenticationType Kerberos
Enable Hyper-V Enhanced Session Mode for a virtual machine:
Set-VM -VMName “YourVMName” -EnhancedSessionModePolicy Allowed
List all checkpoints with details for a virtual machine:
Get-VMSnapshot -VMName “YourVMName” | Format-Table VMName, Name, CreationTime, ParentSnapshotId -AutoSize
Configure Hyper-V host for automatic stop action:
Set-VMHost -AutomaticStopAction TurnOff -AutomaticStopActionTime 120
Check Hyper-V virtual machine replication health:
Get-VMReplication -VMName “YourVMName” | Measure-VMReplication
Modify Hyper-V virtual machine resource metering:
Enable-VMResourceMetering -VMName “YourVMName”
Set a Hyper-V virtual machine to automatically start with the host:
Set-VM -VMName “YourVMName” -AutomaticStartAction Start -AutomaticStartDelay 60
Configure Hyper-V host for shared virtual hard disks:
Enable-ClusterStorageSpacesDirect
Remove a Hyper-V virtual switch:
Remove-VMSwitch -Name “YourSwitchName”
Configure Hyper-V virtual machine automatic start and stop time:
Set-VM -VMName “YourVMName” -AutomaticStartAction Start -AutomaticStartDelay 120 -AutomaticStopAction ShutDown -AutomaticStopDelay 60
Enable or disable Hyper-V Secure Boot for a virtual machine:
Set-VMFirmware -VMName “YourVMName” -SecureBootTemplate MicrosoftUEFICertificateAuthority
Configure Hyper-V virtual machine VLAN ID for network isolation:
Get-VMNetworkAdapter -VMName “YourVMName” | Set-VMNetworkAdapterVlan -Access -VlanId 100
Check Hyper-V virtual machine replication health:
Get-VMReplication -VMName “YourVMName” | Measure-VMReplication
Set Hyper-V host power plan to High Performance:
powercfg /s SCHEME_MIN
Adjust Hyper-V virtual machine memory buffer:
Set-VMMemory -VMName “YourVMName” -Buffer 20%
Enable Hyper-V host Dynamic Optimization:
Enable-ClusterScheduling -DynamicOptimization $true
Set Hyper-V host energy efficiency mode:
powercfg /query SCHEME_CURRENT SUB_SLEEP STANDBYIDLE
powercfg /change standby-timeout-ac 0
powercfg /change standby-timeout-dc 0
Configure Hyper-V virtual machine automatic checkpoints:
Set-VM -VMName “YourVMName” -CheckpointType Production
Set Hyper-V host storage migration performance options:
Set-ClusterParameter -Name CSVEnableBlockCache -Value 1
Are you backing up your Hyper-V Virtual Machines?
BackupChain Supports Hyper-V on Windows 11 as well as Windows Server 2022
BackupChain in an all-in-one Windows backup solution that contains a complete virtual machine backup toolset for Hyper-V, VMware, VirtualBox and other hypervisors. BackupChain can be used to create a live backup of each VM from the host as a local backup or as cloud backup. Apart from backing up VMs, BackupChain offers a wide range of host-level backup features, as well as Granular Backup and Granular Restore to speed up the recovery process.
BackupChain only needs to be installed on the host and each license includes unlimited live virtual machine backup on these main platforms:
- Hyper-V Backup on Windows Server 2022 – 2008 as well as Windows 11 – 8 hosts
- VMware Backup on all Windows platforms
- VirtualBox Backup on all Windows platforms
- Cloud Backup for Virtual Machines
Backup Software Overview
Server Backup SoftwareDownload BackupChain
Cloud Backup
Backup VMware Workstation
Backup FTP
Backup VirtualBox
Backup File Server
Hyper-V Backup
Backup Hyper-VPopular
- Hyper-V Links, Guides, Tutorials & Comparisons
- Veeam Alternative
- How to Back up Cluster Shared Volumes
- DriveMaker: Map FTP, SFTP, S3 Site to a Drive Letter (Freeware)
Resources
- Free Hyper-V Server
- Remote Desktop Services Blog
- SCDPM Blog
- SCOM Blog
- V4 Articles
- Knowledge Base
- FAQ
- Archive 2024
- Archive 2022
- Archive 2021
- Archive 2020
- Archive 2018
- Archive 2017
- Archive 2016
- Archive 2015
- Archive 2014
- Archive 2013
- Hyper-V Scripts in PowerShell
- FastNeuron
- BackupChain (Greek)
- BackupChain (Deutsch)
- BackupChain (Spanish)
- BackupChain (French)
- BackupChain (Dutch)
- BackupChain (Italian)
Backup Software List
BackupChain
Veeam
Unitrends
Symantec Backup Exec
BackupAssist
Acronis
Zetta
Altaro
Windows Server Backup
Microsoft DPM
Ahsay
CommVault
IBM
Other Backup How-To Guides
- Free Disk2VHD Hyper-V VHDX Physical to Virtual Conversion P2V
- What is Deduplication?
- Get All VHDX for All VMs with this PowerShell Script
- Disaster Recovery Strategies and Recovery Objectives
- Windows Server 2012: Hotfixes for Cluster Servers
- How to fix error CLSID {463948d2-035d-4d1d-9bfc-473fece07dab} Access Denied
- KB 2885465: CPU resources are not allocated correctly for VMs on Windows Server 2012
- How to Fix VSS Errors (Volume Shadow Copy Service Errors)
- 9 Editions of Windows Server 2012 Compared At a Glance
- How to Backup a Virtual Server While Running
- 8 Tape Backup Disadvantages and Issues You Need To Know
- How to Resize, Shrink, or Expand VHDX in Hyper-V
- Microsoft Hyper-V Backup for VHD and VHDX VMs
- How to Install a Virtual Machine Inside a Virtual Machine (Hyper-V)
- Copy a File From the Host to a VM Using a Powershell Script
- How to Fix: Folder name too long to delete
- 2 Reasons Why Continuous Data Protection (CDP) Isn’t Always A Good Idea for Backups
- Hyper-V Host Disk Backup, Physical Host and Virtual Machine Backup
- What’s New In Windows Server 2012 and R2?
- 13 Hyper-V Cluster Shared Volume Tips & Tricks