Hyper-V Management with PowerShell

Windows PowerShell Owner’s Manual can be found HERE

PowerShell Management Library for Hyper-V can be downloaded from HERE

The PowerShell management module for Hyper-V: The EDGE video would be available HERE

Although the PS does not need any intro, but still; the PS is a command line tool which enables you to configure Microsoft software’s. As the PS2 is released many months back; the Hyper-V module updated significantly since it’s first release. The following process walkthrough will show you how to import the module successfully.

1. Now first of all download and extract to an empty directory. Run the “bat” file, install the file and follow the process to import the Hyper-V module in the server manager.

 

 

 

 

 

 

2. Now open up the PS and run the following command into it : “Import-Module hyperv”

But you will be presented with an error stating that the module isn’t available in the module directory

3. And after receiving the error run the following commands:

Set-ExecutionPolicy unrestricted

and after that run the following command:

Import-Module hyperv

and since the hyperv module is imported; now you will be able to issue commands related to managing Hyper-V. Issue the following commands for getting the switches:

Get-Command -Module hyperv

The switches would look like the following picture:

4. The new vm command would be like this:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Some more examples:

Connecting to a VM
New-VMConnectSession

Discovering and manipulating Machine states
Get-VMState , Set-VMState , Convert-VmState, Ping-VM , Test-VMHeartBeat, Shutdown-VM , Start-VM, Stop-VM, Suspend-VM, Get-VMKVP, Add-KVP, Remove-KVP, Get-VMJPEG

Backing up, exporting and snapshotting VMs
Export-VM , Import-VM, Get-VMSnapshot, Choose-VMSnapshot , Apply-VMSnapshot , New-VMSnapshot ,Remove-VMSnapshot, Rename-VMSnapShot, Update-VMSnapshot, Get-VMSnapshotTree, Get-VmBackupScript

Adding and removing VMs, configuring motherboard settings.
New-VM , Remove-VM , Set-VM , Get-VMCPUCount, Set-VMCPUCount, Get-VMMemory, Set-VMMemory, Set-VMSerialPort

Manipulating Disk controllers, drives and disk images
Get-VMDiskController
Add-VMSCSIController , Remove-VMSCSIcontroller
Get-VMDriveByController , Add-VMDRIVE , Remove-VMdrive
Get-VMDiskByDrive, Add-VMDisk , Set-VMDisk, Get-VMDisk
Get-VMFloppyDisk , Add-VMFloppyDisk
Add-VMNewHardDisk

Manipluating Network Interface Cards
Get-VMNic , List-VMNic , Choose-VMNIC, Add-VMNIC, Remove-VMNIC , Set-VMNICAddress , Set-VMNICConnection , Get-VMNicport,
Get-VMNicSwitch, Choose-VMSwitch, New-VMSwitchPort, Get-VMByMACaddress, Choose-VMExternalEthernet,
New-VMExternalSwitch, New-VMInternalSwitch, New-VmPrivateSwitch

Working with VHD files
Get-VHDDefaultPath, Get-VHDInfo, New-VHD, Compact-VHD, Test-VHD,Convert-VHD,Merge-VHD,Mount-VHD, Unmount-VHD

 

Now enjoy!!! and do NOT forget to test these in an R&D environment. NEVER TEST in the production server unless you know what you are doing 😀