Creating Provisioning Services & XenDesktop Virtual Desktops on Windows Server 2012 Hyper-V using PowerShell!
Click to download: WS2012_HyperV_PVS_XenDesktop_StreamedVM_Setup_Wizard.ps1
I was recently asked to do a hypervisor performance comparison using LoginVSI against Windows Server 2008 R2 SP1 Hyper-V 2 and the newly released Windows Server 2012 Hyper-V 3. For this scenario we would need to spin up a number of virtual desktops on Hyper-V 2.0 and Hyper-V 3.0 using Citrix Provisioning Services and Citrix XenDesktop for the connection broker. This was a very exciting project for me, but seeing that Windows Server 2012 is not yet supported for use with PVS or XenDesktop, I had to be a bit creative in the virtual machine creation process. Additionally, XenDesktop will treat these virtual machines as physical devices and will not have any power management capabilities.
Seeing that Windows Server 2012 now ships with PowerShell v.3, I figured the task wouldn’t be too terribly difficult to tackle. I would simply need to create a template VM just as I had done for numerous XenDesktop on Hyper-V deployments, then clone this template a number of times to reach my desired desktop count. Once the desktops were cloned, a report with all the MAC addresses could then be imported into PVS to attach to the appropriate vDisk and AD Machine accounts could be created. The last step is to create a catalog and desktop assignment group for brokering connections to the VDA through XenDesktop. Below I will cover a couple lessons learned with the initial development of the script.
For this exercise I intentionally wanted to bypass the use of System Center and create all the VMs directly from Hyper-V. Technically System Center VMM 2012 SP1 (currently in CTP) would be able to manage the WS2012 Hyper-V boxes, but I would still have complications obtaining all the MAC addresses once created. Therefore, I decided to use an all Hyper-V/PowerShell method to export the template and repeatedly import the template.
Issue: Exporting and importing a virtual machine with a hard disk attached is problematic.
Solution: detach the disk, export the VM, import and rename the new VM, copy the detached disk to the new VM location, attach the disk to the new VM.
Issue: MAC addresses are not allocated to newly imported VMs until they are powered on.
Solution: Power on the virtual machine long enough to obtain a MAC address, then force a power off operation. At this point a MAC address has been allocated and can be retrieved and logged.
Below is a sample output, post execution:
I am also including a several minute video demonstrating the use of the powershell script and showing a virtual desktop being brokered through XenDesktop 5.6 using PVS 6.1 and Windows Server 2012 Hyper-V 3!
If you have any questions, comments, or just want to leave feedback, please do so below. Thanks for reading!