Manage Hyper-V using PowerShell?

Hello everyone,

In this tutorial I am going to guide you some useful, Powershell commands for Hyper-V, You surely asked yourself why am I need manage Hyper using Powershell if I can manage it through the GUI? Give me a chance to explain, What if your boss asks you to create 20-30 machine of the same operating system, same RAM, and CPU resources? What if your boss asks you to generate the utilization virtual machines report? What if your boss asks to retrieve to CSV file all United State machine that belongs to specific switch?

Pretty convincing?

You can find out all Hyper-V command by running:

Get-Command –Module Hyper-V

Here is the long list:

Manage Hyper-V PowerShell

The first command you have to introduce is:

Get-VM

post-479-0-93681900-1428706168.jpg

Ho to power on virtual machines?

Start-VM Name Windows Server 2012R2

post-479-0-43318300-1428706473.jpg

Manage Hyper-V PowerShell

How to stop the virtual machine?

Stop-VM Name Windows Server 2012R2

How to create a new virtual machine?

Set your PowerShell mode as “Unrestricted” mode.

With the following command, I am just creating VHDX file ( there is no ISO file yet)

New-VM -Name “Windows Server 2008R2” -MemoryStartupBytes 1024MB -NewVHDPath c:\Win2k8R2.vhdx -NewVHDSizeBytes 40GB

Manage Hyper-V PowerShell

Manage Hyper-V PowerShell

 VHDX location:

Manage Hyper-V PowerShell

How to create “vmswitch” ?

Do not forget to specify ‘NetadapterName” parameter you can find out it using:

Get-netadapter

Create “vmswitch” ?

New-VMSwitch -Name "labs" -NetAdapterName "Ethernet"

Manage Hyper-V PowerShell

The last command I want to show you is to remove Virtual Machine:

Remove-VM –Name “Windows Server 2008R2”
You have to confirm with Y

Manage Hyper-V PowerShell