Using PowerCLI and OS Customisations to Rapidly Provison a Q/A Environment

In this example below I've presented a PowerCLI script that will provision 20 desktop VMs to be used wihtin a Q/A testing process to support Automated Testing

# We will name the VMs “QAVMUD-01”, “QAVMUD-02”.....

Step 1:  Source Control Your Configuration

a. Download GIT for Windows
b. Create a new folder structure for your project e.g.
mkdir c:\devops\irm\qabuild\git
cd c:\devops\irm\qabuild\git
git init --bare # which creates a new git repo
c. Create a file to hold the list of static IPs you wish to assign
192.168.0.11
192.168.0.12
192.168.0.13
............

md c:\devops\irm\qabuild\working
cd c:\devops\irm\qabuild\working
git clone c:\devops\irm\qabuild\git

Step 2:

$strNameTemplate = “QAVMWSUD-{0:D2}” # QA / Virtual Machine / Windows / User Desktop / Two Digit 00...99

$objCluster = Get-Cluster LocalDC-Non-Production
$objTemplatee = Get-Template QATMPLWIN8UD

$objVMList = @()

for ($i = 1; $i –le 20; $i++)
{
$strVMName = $strNameTemplate –f $i
$objVMList += New-VM –Name $strVMName –ResourcePool $objCluster –Template $objTemplate

}

$staticWindowsIPList = Import-CSV c:\devops\irm\qabuild\working\git\WindowsQAIPs.csv

$objWindowsSpec = New-OSCustomizationSpec –Name WindowsCustomization –Domain abbeydev.com –DnsServer “192.168.0.100”, “192.168.0.110” –NamingScheme VM –OSType Windows

$objWindowsSpecClone = New-OSCustomizationSpec –Spec $objWindowsSpec –Type NonPersistent

for ($i = 0; $i –lt $objVMList.Count; $i++)
{
$ip = $staticWindowsIPList[$i].IP
$nicMapping = Get-OSCustomizationNicMapping –OSCustomizationSpec $objWindowsSpecClone

$nicMapping | Set-OSCustomizationNicMapping –IpMode UseStaticIP –IpAddress $ip –SubnetMask “255.255.252.0” –DefaultGateway “192.168.0.1”

Set-VM –VM $objVMList[$i] –OSCustomizationSpec $objWindowsSpecClone –Confirm:$false

}

So what is the advantage of this

Well one very simple change you could make

Make the VM Template, OS Type parameters and this gives you the ability to create a QA environment with the same code as you require.








Comments

Popular posts from this blog

Basic Send Message to MQ with Java and IBM MQ JMS

Basic Receive Message to MQ with Java and IBM MQ JMS

Creating a simple Alert / Success Message with ASP.NET/VB using Bootstrap