Hyper-V PowerShell modules included with Windows Server 2012 will make it easier to streamline virtualization administration without System Center Virtual Machine Manager (SCVMM), but there are some important changes to PowerShell cmdlets to note.
It will still be easier to make mass changes across your virtual environment with SCVMM 2012, but in most cases, the built-in Hyper-V cmdlets are more than adequate for operations such as creating VMs, modifying attributes and monitoring VM usage.
Hyper-V PowerShell cmdlets in Windows Server 2008 R2 were straightforward and functional, but they required a PowerShell module from CodePlex that was not built into Windows Server 2008. This method worked for basic tasks, but left SCVMM as the only option for advanced Hyper-V PowerShell scripting -- meaning added software and hardware costs for many organizations.
All the functionality of the Hyper-V PowerShell cmdlets are still in the new version of Hyper-V, but many of the cmdlets have changed, so moving your Hyper-V R2 PowerShell scripts will require a learning curve to get you up to speed with the new syntax.
Let's look as some of the differences between the Windows 2008 R2 Hyper-V and Hyper-V 2012 PowerShell cmdlets, as well as a basic script I have been working with on the new platform.
You can download the Hyper-V scripts referenced in this article.
The comparison between Hyper-V versions above are simple scripts that create a VM using a parent VHD volume that has prompts for a VM name, as well as dynamic memory minimums and maximums.
PowerShell cmdlet differences
The first big change you will see between the two scripts is Line 3 to Line 7. The CreateVMR2.ps1 script loads the external Hyper-V PowerShell module. You no longer need that step in your Hyper-V 2012 PowerShell scripts, because Hyper-V loads it by default when you open PowerShell.
Getting down to the section of the scripts that create the VM, you can see where the syntax really starts to diverge. New-VM stays the same, but when adding CPUs to the VM, we have a new cmdlet, Set-VMProcesssor (CreateVM2012.ps1 / Line 33) instead of Set-VMCPUCount (CreateVMR2.ps1 / Line 35).
You can also see that the –VM switch is now –VMName in Hyper-V 2012. The command that set the number of CPUs assigned to the new VM is –Count instead of –CPUCount.
There are also changes to note when looking at the addition of a network adapter. Add-VMNic (CreateVMR2.ps1 / Line 37) is now Add-VMNetworkAdapter (CreateVM2012.ps1 / Line 35) along with the change in the switch for the virtual network switch from –VirtualSwitch to –Switchname.
New PowerShell cmdlets for setting VM parameters
Moving down to setting VM memory, you will see that the Set-VMMemory cmdlet is the same, but the switches to set Dynamic Memory have changed significantly. The –dynamic cmdlet (CreateVMR2.ps1 / Line 36) is now –DynamicMemoryEnabled (CreateVM2012.ps1 / Line 34). The –MinimumBytes and –MaximumBytes switches are now part of the newest version of Hyper-V cmdlets instead of the previous –limit.
The PowerShell cmdlets used for adding a virtual hard drive (VHD) have also changed. The cmdlet to create a new VHD is the same, New-VHD, but the switches that define the file paths to the VHD locations have been changed from –VHDPaths and –ParentVHDPath (CreateVMR2.ps1 / Line 40) to –Path and –ParentPath (CreateVM2012.ps1 / Line 38).
Attaching the disk requires another cmdlet change from Add-VMdisk (CreateVMR2.ps1 / Line 46) to Add-VMHardDiskDrives (CreateVM2012.ps1 / Line 44), as well as a complete overhaul of the switches used to set the type of controller and controller number: –ControllerID to ControllerType and –LUN to ControllerNumber.
Along with changes in cmdlets and switches, there are a number of new options available for the new features found in Windows Server 2012 Hyper-V.
These examples are by no means the only PowerShell cmdlet differences found Windows Server 2008 R2 Hyper-V and Windows Server 2012 Hyper-V, but act as samples of what to expect when moving to the new Hyper-V platform. Some translation of your existing scripts will be necessary, but with the addition of expanded granular cmdlets as well as new cmdlets for new features found in the latest version of Hyper-V, it will be a worthwhile exercise.
Dig Deeper on Microsoft Hyper-V management
Rob McShinsky asks:
Are you finding PowerShell cmdlet changes difficult to navigate?
0 ResponsesJoin the Discussion