Deployment–The PDT VM Creator

Deployment–The PDT VM Creator

  • Comments 30
  • Likes

I introduced the PowerShell Deployment Toolkit, or PDT, in a previous post.  As I mentioned in that post, PDT requires that the servers that System Center will be deployed to are already running, members of an Active Directory domain, and you have administrator permissions to those servers.  PDT includes a script to help create Hyper-V VMs for this purpose – VMCreator.ps1.  This post explains how to use and customize VMCreator.ps1.

VMCreator.ps1 will create any number of VMs for you on one or more standalone Hyper-V hosts.  Note that the current version will not create highly available VMs on a Hyper-V cluster.  VMCreator.ps1 takes input from the <VMs> section of the variable.xml file in the same folder.  Under <VMs> there are two required entries – <Count> specifies how many VMs to create, and <Default> specifies the default settings for each VM to be created.  Most of the entries under <Default> are fairly self-explanatory, but there are a few that need a little more detail:

  • <VMName> lists a prefix and a starting sequence number.  In the sample variable.xml file with PDT, it uses “Server” as the prefix and starts the sequence at 11.  So VMCreator.ps1 will create VMs called Server11, Server12, Server13, etc.
  • The <NetworkAdapter> section has two optional settings – <MAC> and <IP>.  These are used if you want to specify static MACs and IPv4 addresses – if you want those to be dynamic, just delete those sections.
  • <OSDisk> specifies the parent VHD for the operating system drive.  This must be a sysprepped VHD for the operating system version you wish to install, and must be a single partition VHD.  The easiest way to create this parent disk is to use Convert-WindowsImage.ps1 and just create the VHD from the Windows Server media.
  • <PagefileDisk> is optional – but allows you to specify a VHD that will be used as the D: drive.  In my lab, I always move the pagefile to the D: drive to allow me to wipe it whenever it gets bloated.  If you don’t want to do this, just delete this section also.
  • <DataDisks> is also optional – so you can create disks other than the operating system drive.  If you want data disks of different sizes, you can use multiple <DataDisks> sections, or if you just want the operating system drive, you can delete the section.
  • Under <JoinDomain>, <OrganizationalUnit> is also optional.  If you want to use the default AD container for new computer accounts, just delete the <OrganizationalUnit> section.

If you want specific settings other than the defaults for individual VMs, such as creating specific VMs on a Hyper-V host other than the default, you can add a <VM> section at the same level as <Default>, and specify individual settings in that section.  The section header must specify the VM number.  All settings not specified in the <VM> section will still be used from <Default>.  For example:

<VM Count="1">
< /VM>

Finally, VMCreator.ps1 must be run from a Windows Server 2012 system that has the Hyper-V PowerShell module installed.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Hi Rob great script.  

    A couple of thoughts for the next version could the following please be included.

    Time Zone.  (Having to change it for every deployed server is a pain)

    Vlan for Nic's

    Language settings (Not everyone in the world is based in the USA)

    would it be possible to include a custom script section so it would be possible to add in additional roles / features / commands / scripts.  (This way a DC could be promoted as the first machine then the others come up 3 minutes later ?).

    If interested i have all the code for the first 3.


  • Just a warning it seems that all computer names are created in upper case when using PDT.  This means if you have in your xml file scvmm-svr1 then you will not be able to install vmm as the deploy script will add this in SCVMM and then it wont install :)

  • Great script, however I am seeing errors at the end of each VM creation point. I have saved the output from server10 to a text file I can send to you.

    Here are the high points:

       Mounting D:\VMs\Server20\Virtual Hard Disks\Server20.vhdx

         D:\VMs\Server20\Virtual Hard Disks\Server20.vhdx mounted as F G:

         Inserting unattend.xml

           Join domain: corp.rx8.loc

           Join domain credentials: <scrubbed>

           Installer service account: <scrubbed>

           Organizational unit: OU=Servers,<scrubbed>,DC=loc

    Out-File : Cannot find drive. A drive with the name 'F G' does not exist.

    This action repeats for each time unattend.xml is attempted to be written to. Looks like $Drive is being interpreted as "F G:", so unattend.xml is not present when the VM boots.

  • In addition to the comments by Davey Rance, I would like to either see a Contoso DC built with the correct users & groups, or an additional file to use to populate an existing AD with the required users.

  • Following on Davey's comment, a separate script to create the necessary Contoso domain, or a script to create the required users/installer/service accounts in an existing domain would be a fantastic option.

    Secondly, I am having an issue where the script is trying to mount the VHD for drive C as drive "F G:". This is preventing the unattend.xml file from being updated and saved to the boot drive. The error occurs starting with line 325, where it is starting to assign values to variable $Drive.

    Great work on the scripts, I was finally able to complete the download of all of the files called by Downloader.ps1.

  • Davey - great feedback, I will certainly look at those for the next revision.  As for including a DC setup in VMCreator, I showed a preview of that in my MMS 2013 session, which can be viewed here -->

  • Davey - had not run into the case issue before, I will look into it and resolve in a future revision.

  • NBowman - your parent VHD has multiple partitions, which is what causes this.  The post states that it must be a single partition.  If you install then sysprep, you get multiple partitions.  Using Convert-WindowsImage.ps1 creates a single partition parent.  The next revision of VMCreator will resolve this so you can use multiple partition parents created though install then sysprep.

  • NBowman - the next revision will include the ability create VMs include AD and initiate an install in a single pass.  I previewed this in my MMS 2013 session, which can be viewed here -->

  • Thanks Rob. Using the Convert-WindowsImage.ps1 did correct my issue. The VMs created perfectly, and after editing the Variables.xml, did have them join my AD in the correct OU.

  • Hey Rob - Great work!

    Is there a way to deploy without the use of differencing disks?

  • Ted - to create standalone disks instead of differencing disks, you can change "Differencing" to "Copy".

  • Hi Rob.  Another small thing is that it seems that the orchestrator firewall rule is skipped / not added in.

    But i was able to deploy out a full Private cloud environment which was just great.

    Regarding the DC's i also have 3 additional files that can be added in to complete the build for


  • Hi Rob.

    Another small thing with the install of Orchestrator would it be possible to add in the runbook service account rather than just using the management account for everything.



  • Rob it seems that the ip address / domain join doesn't quite work when deploying out a windows 2008 R2 server.