Hyper-V related PowerShell cmdlets

Check out some important powershell cmdlets that can be used to do some cool tasks in Hyper-V Server 2012. Need to replace only those parts which are in bold and italics, as required.

Create a New VM

  • New-VM –Name “VMName” –MemoryStartupBytes MemoryinGB

Create a New VHD

  • New-VHD –Path VHDPath –SizeBytes SizeinGB
  • New-VHD –ParentPath ParentPath –Path ChildPath -Differencing

Second command creates a differencing disk based on the parent disk.

Create a New Virtual Switch

  • New-VMSwitch “SwitchName” -NetAdapterName “Network Adapter Name” -MinimumBandwidthMode Weight

Add and connect a virtual network adapter to a switch

  • Add-VMNetworkAdapter –VMName VMName –Name “NICName” -SwitchName SwitchName

Create an ACL in an adapter

  • Add-VMNetworkAdapterAcl –VMName VMName –RemoteIPAddress IP/Subnet –Direction Both –Action Allow

Replace –RemoteIPAddress with –RemoteMacAddress to use Mac address.

Create a VM Snapshot

  • Checkpoint-VM -Name VMName -SnapshotName SnapshotName

Connect a virtual adapter to a virtual switch

  • Connect-VMNetworkAdapter -VMName VM1,VM2 -Name AdapterName -SwitchName SwitchName

Enable replication of a VM

  • Enable-VMReplication VMName Replica Server FQDN PortNumber Kerberos

Port Number is used to direct replication traffic.

Enable migration of a VM

  • Enable-VMMigration

Enable Resource metering

  • Enable-VMResourceMetering –ResourcePoolName ResourcePoolName –ResourcePoolType Type

Replace –ResourcePoolName with the –VMName for collecting a particular VM’s resource utilization data. Choose Type as Memory, Processor or Ethernet etc.

Retrieve BIOS details of a VM

  • Get-VMBios VMName

Retrieve Configuration and NUMA topology of a Hyper-V host

  • Get-VMHost


Retrieve virtual network adapters of a VM

  • Get-VMNetworkAdapter –VMName *

*indicates from all VM’s

Restart VM

  • Restart-VM VMName

Restore a VM Snapshot

  • Restore-VMSnapshot –Name ‘SnapshotName‘ –VMName VMName
  • Get-VM | Foreach-Object {$_ | Get-VMSnapshot | Sort CreationTime | Select -Last 1 | Restore-VMSnapshot -Confirm:$false}

Second command applies the most recent snapshot on all VM’s without any confirmation prompts.

Configure VM BIOS (Generation 2 VM’s)

  • Set-VMBios VMName -StartupOrder @(“Floppy”, “LegacyNetworkAdapter”, “CD”, “IDE”)

Command to configure the boot device order.

Configure virtual network adapter’s features

  • Set-VMNetworkAdapter -VMName VMName -DhcpGuard On –PortMirroring Source

Enables DHCPGuard and PortMirroring. DHCPGuard, if enabled drops those packets, which are the replies to requests from DHCP clients. Enabling port mirroring copies every packet sent or received to a monitoring VM.

Validate configured replication connection

  • Test-VMReplicationConnection Replica ServerPort Number Kerberos

Check here to find more cmlets…


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s