My Experience With The PowerShell Deployment Toolkit (PDT) – Part 2 (VMCreator.ps1)

In our last post, we used the PDT’s Downloader.ps1 script to download all the files, pre-requisites, etc. that are required to setup all System Center components.

Now, we are going to use the VMCreator.ps1 script to create all the VMs we need.

For more information about the VMCreator.ps1, see the following: http://blogs.technet.com/b/privatecloud/archive/2013/02/18/deployment-the-pdt-vm-creator.aspx

IMPORTANT: This script only support creating of VM’s on Microsoft Windows Server Hyper-V.

Variable.xml File

The PDT2.5.2509 directory contains 2 important files, called Variable.xml, and VariableAD.xml. This is the file that tells the script what to label the VMs, etc.

NOTE: The file “Variable.xml” will create all VMs created for System Center, but requires the existing of Active Directory first. The file “VariableAD.xml” will create all the VMs including a Domain Controller with Active Directory. This is the best option to use if you want to re-build your lab environment completely automated. This is the file that I will be using.

Let’s first take a look at this file, so that I can point out the area(s) you may want to customize.

Start by editing the VariableAD.xml file.

VariableADXML

There are a few things to note.

First, you should take note that the domain used is “CONTOSO”. If you want to customize your setup to have a specific domain name, you will need to Find and Replace all entries of “CONTOSO” with your domain.

In my lab example, I am going to change it to “SC.LAB”. However, there are 2 different types of entries that contain the word “CONTOSO”. One for Service Accounts, using the ‘DomainUserName’ pattern (44 entries), and another that uses ‘Domain.com’ (46 entries) for the database server references.

VariableADXML-ChangeDomain

Therefore, to make it easier to use Find and Replace, I have found that replacing the ‘Domain.com’ references first is best. In my case I will use Find and Replace and replace the existing “Contoso.com” with “SC.LAB”. If your domain uses the “.com” ending, then you can just simply replace all entries of “CONTOSO” with your domain name.

Once you have the domain modified, save the file as “Variable.xml” replacing the existing one, or you can name it something specific like “VariableADCustom.xml”.

VMCreator.ps1 Script

Now that we have a customized Variable.xml file, we are ready to make a few minor modifications to the VMCreator script and then run it.

If you have re-named the Variable.xml to something different, you will need to edit the VMCreator script first (because by default it looks for Variable.xml). I have not attempted this yet, so re-name your XML file to be “Variable.xml”. Once I have attempted with a re-named file, I will post an update to this section.

Now, before we can run the VMCreator script, we need to create a sysprep’d VHD file for each OS required (namely Windows Server 2008 R2, and Windows Server 2012 R2). To make this easy, you can use the Convert-WindowsImage.ps1 script (found here: http://gallery.technet.microsoft.com/scriptcenter/Convert-WindowsImageps1-0fe23a8f).

Convert-WindowsImage.ps1 Script

Using this command-line tool allows you to rapidly create sysprepped VHDX and VHDX images from setup media for Windows 7/Server 2008 R2, Windows 8/8.1/Server 2012/R2.

This script actually has a GUI to make it easier to work with, which I will walk though here.

Start by running PowerShell command prompt as Administrator. Right-click on PowerShell and choose ‘Run As Administrator’.

Administrative PowerShell Prompt

In the PowerShell command prompt, change the working directory to where the Convert-WindowsImage script is located (in my example, in the Downloads folder); for example: cd “C:UsersAdinDownloads”.

Now call the script, and include the “-ShowUI” parameter, like this: Convert-WindowsImage.ps1 -ShowUI. This will cause the GUI to appear.

ConvertWindowsImage-UI

From this UI, choose 1). the Source (which is the ISO of your Operating System), 2). the SKU (like Standard, Enterprise, Datacenter, etc.), 3). specify the file format (I choose VHDX for 2nd Generation VMs running Windows Server 2012), Dynamic, and the size (I left mine at the default of 40 GB).

Leave the Working Directory as is, since that’s where the script is running from. Provide a name for the VHD file.

NOTE: If you do choose to provide a name, you MUST enter the file extension or else you will encounter an error as follows (i.e. W2012R2.vhdx).

INFO : Launching UI…
INFO : Opening ISO en_windows_server_2008_r2_with_sp1_vl_build_x64_dvd_617403.iso…
INFO : Looking for F:sourcesinstall.wim…
INFO : Scanning WIM metadata…
ERROR : There is a mismatch between the VHDPath file extension (), and the VHDFormat (.VHDX). Please ensure that these
match and try again.
INFO : Log folder is C:UsersAdinAppDataLocalTempConvert-WindowsImagefe5ad446-cd0a-4e4d-b72b-f5916feb7d9e
INFO : Done.

ConvertWindowsImage-UI_ErrorOutput

When you are ready, click the Make My VHD button.

Windows(R) Image to Virtual Hard Disk Converter for Windows(R) 8
Copyright (C) Microsoft Corporation. All rights reserved.
Version 6.3.9600.3.amd64fre.fbl_core1_hyp_dev(mikekol).131226-2000 Release to Web

INFO : Launching UI…
INFO : Opening ISO en_windows_server_2012_r2_x64_dvd_2707946.iso…
INFO : Looking for D:sourcesinstall.wim…
INFO : Scanning WIM metadata…
INFO : Image 2 selected (ServerStandard)…
INFO : Creating sparse disk…
INFO : Attaching VHDX…
INFO : Disk initialized with MBR…
INFO : Disk partitioned…
INFO : Volume formatted…
INFO : Access path (F:) has been assigned…
INFO : Applying image to VHDX. This could take a while…
INFO : Signing disk…
INFO : Image applied. Making image bootable…
INFO : Opening F:bootbcd for configuration…
INFO : BCD configuration complete. Moving on…
INFO : Drive is bootable. Cleaning up…
INFO : Generating name for VHDX…
INFO : Closing VHDX…
INFO : Closing Windows image…
INFO : Done.

The script will show in the PowerShell command prompt what it is doing.

ConvertWindowsImage-UI_Output

You will need to create 2 VHDs, one for Windows Server 2012 R2, and another for Windows 2008 R2. This is required because the System Center Service Manager portal runs on SharePoint 2010, which is only supported on Windows Server 2008 R2.

Variable.xml File (VHD Files)

Now that we have the sysprep’d VHD files ready, we can now use the VMCreator.ps1 script to create all the Virtual Machines (VMs) for all the System Center components automatically.

By default, the VMCreator.ps1 script uses the Variable.xml file to generate the VMs. Therefore, by default it will check for the VHD file in the following location: C:VHDWS12R2D.vhdx.

This means that you will have to either move/re-name your sysprep’d VHD file, or change the XML file to point to the correct location. In my example, I will change the XML file accordingly, as follows.

At line # 235 the section begins. Within there, there is a reference to which is the sysprep’d VHD file that we created (specifically the Windows Server 2012 R2 disk). Change this entry to meet the location and name of the VHD file you created with the Convert-WindowsImage.ps1 script.

<OSDisk>
<Parent>C:VHDWS12R2D.vhdx</Parent>
<Type>Differencing</Type>
</OSDisk>

At line # 399 the  section begins. Within there, there is a reference to which is the sysprep’d VHD file that we created (specifically the Windows Server 2008 R2 disk). Change this entry to meet the location and name of the VHD file you created with the Convert-WindowsImage.ps1 script.

<OSDisk>
<Parent>C:VHDWS08R2E-SP1.vhdx</Parent>
<Type>Differencing</Type>
</OSDisk>

Variable.xml File (Virtual Switch)

Before you run the script, you also need to ensure that the Hyper-V Virtual Switch is already created.

In the Variable.xml file, at line # 222 the section begins. Change this entry to match whatever Virtual Switch you have created in Hyper-V, or create a Virtual Switch labelled the same “CorpNet01”.

<VirtualSwitch>CorpNet01</VirtualSwitch>

In my lab example, I created an Internal Virtual Switch, and labelled it “Internal Lab Virtual Switch”.

 

Variable.xml File (VHD Location)

One more minor note. In the Variable.xml file, at line # 208 and 209, there is a and reference. On your Hyper-V host, if you have a different drive that you want your VM files to be stored on, you need to change this reference. In my lab example, I have a dedicated SSD drive labelled as Y: for my VMs.

<VMFolder>C:VMs</VMFolder>
<VHDFolder>C:VMs</VHDFolder>

Now we are finally ready to run the VMCreator.ps1 script and watch it create all the VM’s for us!

VMCreator.ps1 Script (Continued)

Start by running PowerShell command prompt as Administrator. Right-click on PowerShell and choose ‘Run As Administrator’.

Administrative PowerShell Prompt

In the PowerShell command prompt, change the working directory to where the VMCreator.ps1 script is located (in my example, in the Downloads folder); for example: cd “C:UsersAdinDownloads”.

Now run the script: VMCreator.ps1. The command line will show you its progress. First it will validate everything, and then start creating the VMs. You will notice that it first creates the Active Directory Domain Controller, and waits for that to be up and running (with Domain Services installed), and then create the other VMs. This is because all other VMs are joined to the domain.

VMCreator-AD

VMCreator-AllVMs

Once all the Virtual Machines are up and running the script will appear to be completed, as follows.

VMCreator-VMsCompleted

However, if you connect to the Domain Controller, you will see that another script is running to install all the components for each System Center product.

VMCreator-DC-ComponentInstall

Eventually, you will notice that some lines will turn yellow. This is because some elements are dependant on others, so it needs to wait for those to complete. For example, SQL Server needs to be installed before Management Servers, Management Servers need to be up and running before Consoles are installed, etc.

PDT Installations Pending

When an element is complete, the line will turn green.

PDT Installations Completed

This entire process will take some time, and is dependant on your hardware. In Microsoft’s MMS demo, it took them just less than an hour. With my lab hardware (described here), it took approx. 1 and a half hours.

In the last post in this series, we will go onto using the next script, Installer.ps1.

3 thoughts on “My Experience With The PowerShell Deployment Toolkit (PDT) – Part 2 (VMCreator.ps1)

  1. Leon

    Can you provide me what kind of virtual switch yoy created; External internal or pivate for your test scenario? It makes this bolg post just a little bit better. Keep up the good work!

%d bloggers like this: