Share via


Powershell 4.0 Usage in Hyper-V Windows Server 2012 R2

An Introduction about PowerShell 4.0, Hyper-V in Windows Server 2012 R2

I have started experimenting with Hyper-V capabilities on Windows Server 2012 R2, the brand new Server came on-board in recent days. Microsoft has added 2,300 new cmdlets to Server 2012 and more than 160 of them enable you to manage Hyper-V. Prior to Server 2012 and PowerShell 4.0, you had to use either the Hyper-V cmdlets that were part of Microsoft System Center Virtual Machine Manager (VMM) or CodePlex’s PowerShell Management Library for Hyper-V. With Server 2012, PowerShell 4.0 has effectively eliminated the need to use the Hyper-V cmdlets in VMM or the CodePlex library. That means, if you’re still running PowerShell 4.0 on Windows 8, Windows Server 2008 R2, or Windows Server 2008, you still need to use the Hyper-V cmdlets in VMM or the CodePlex library. To see the entire list of new cmdlets for Hyper-V, check out TechNet’s Hyper-V Cmdlets in Windows PowerShell web page.

How to Create new VM?

I am trying to make a VM with the following specifications:

VM Name: Hyp-1
Memory Start up bytes: 512 MB
VHD file Path: C:\Manu\Hyp-1\hyp-1.vhdx
VHD Size in Bytes: 60GB

The cmdlet developed for the same is as follows:

New-VM -Name “Hyp-1″ -MemoryStartupBytes 512mb -NewVHDPath C:\Manu\Hyp-1\hyp-1.vhdx -NewVHDSizeBytes 60000000000

See below to understand how to make sure that we are in right path !

http://microsoftservers.in/wp-content/uploads/2014/02/vm1.png

More Stuffs!

See, how we can enhance the VM we created just now:

  1. Add an additional Network adapter
  2. Increasing the processor count
  3. Add an additional DVD Drive
  4. Add Extra VHD and add it as a new disk
  5. Add a new SCSI controller

Add an Additional Network Adapter

The following cmdlet adds an extra network adapter with name ‘Lan1′

Add-VMNetworkAdapter -VMName hyp-1 -Name “Net1″

Also see the result of the operation as shown below:

http://microsoftservers.in/wp-content/uploads/2014/02/vm2.png

Increasing the Processor Count

Following cmdlet increases the processor count of the VM to 2

Set-VMProcessor -VMName hyp-1 -Count 2

See the result as below

http://microsoftservers.in/wp-content/uploads/2014/02/vm3.png

Add an Additional DVD Drive

Add an additional DVD Drive by executing the following cmdlet:

Add-VMDvdDrive -VMName hyp-1

See the result as below

http://microsoftservers.in/wp-content/uploads/2014/02/vm4.png

Add Extra VHD and add it as a new Disk

The following cmdlet adds a new VHD file in the required location and later it can be used as an additional Disk on the VM. I am creating a dynamic disk with 10gb size

New-VHD -Path C:\Manu\Hyp-1\Disk2.vhdx -Dynamic -SizeBytes 10gb

http://microsoftservers.in/wp-content/uploads/2014/02/VM5.png

How to use the vhd as an additional disk on the vm

Add-VMHardDiskDrive -VMName Hyp-1 -Path C:\Manu\Hyp-1\Disk2.vhdx

http://microsoftservers.in/wp-content/uploads/2014/02/vm6.png

Add a New SCSI Controller

The following cmdlet can add a new SCSI Controller to the VM

Add-VMScsiController -VMName Hyp-1

http://microsoftservers.in/wp-content/uploads/2014/02/vm7.png

And finally, we are going to check the entire properties of the VM through the following cmdlet:

Get-VM -VMName Hyp-1 |fl *

http://microsoftservers.in/wp-content/uploads/2014/02/vm8.png