I recently had the opportunity to work with the PowerShell Deployment Tool kit (PDT). The PowerShell Deployment Toolkit is a set of scripts and xml files that helps automate the build out of System Center servers. It’s absolutely the coolest set of scripts.
VMCreator.ps1 is the script that automatically builds the VMs and installs the OS. It relies on a Variable.xml file which can be configured for your farm deployment. This is a general tool and not System Center specific.
In this post I’ll be sharing my simplified version of VMCreator.ps1 – called CreateVM.ps1. Having seen what VMCreator does, I’ve modified it to be able to spin up single base VMs passing parameters on the command line. It runs on Windows Server 2012 and creates a VM on the server that the script executes on. The VMs are created based on existing .vhd or .vhdx files. These files can be created through the use of Create-WindowsImage.ps1 and a windows .ISO file.
The script accepts the following parameters:
- VMname – the name of the VM to be created
- VMFolder – the folder where the VM will be placed
- OSDisk – the name of the OS disk (.vhdx) to create the VM
- Memory – amount of memory in MB to allocate to the VM
- CPU – number of CPUs to allocate to the VM
Syntax: .\CreateVM –VMName DB01 –VMFolder d:\VMs –OSDisk d:\VHD\WIN2012.vhdx –Memory 4096 –CPU 2
Worth noting is the creation of Windows Setup unattend.xml file. Unattend.xml automates the installation of the Windows OS in the VM. It enables you to script the installation with configuration information such as Computer name, IPAddress, Domain to join, Service accounts and Administrator password, just to name a few. The installation executes without having to log in – saving you from doing all the mundane tasks.
In this script, Unattend.xml is created dynamically as the script runs and it’s written off to a file within the VM. Note the @” and “@ symbols that encapsulate the xml. Also note the variables that are being used within the xml.
<?xml version=”1.0″ encoding=”utf-8″?>
<component name=”Microsoft-Windows-Shell-Setup” processorArchitecture=”amd64″ publicKeyToken=”31bf3856ad364e35″ language=”neutral” versionScope=”nonSxS” xmlns:wcm=”http://schemas.microsoft.com/WMIConfig/2002/State” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”>
“@ | Out-File “$Drive`:\unattend.xml” -Encoding ASCII
Download the script and try it out – I hope it saves you a bunch of time. CreateVM
Rename it from .txt to .ps1
Also, checkout the PDT – I guarantee you will be amazed!