Search This Blog

Tuesday, September 2, 2014

Create Virtual Machine Using PDT

In this post we are going to look on another alternative way to create virtual machine. The tool that we are going to use is Microsoft Powershell Deployment Toolkit (PDT). We have modified the default PDT variable to just use it for

  • Provisioning a virtual machine with different configuration
  • Assign IP Address
  • Join to Domain

This come handy when you just would like to provisioning several virtual machine without install any roles/application and then pass Application team for application deployment.

Pre-requisite:-

a) Windows Server 2012 R2 Hyper-V

b) Downloaded PDT from Technet Gallery:- Click here

c) Base image either Windows Server 2008 R2, Windows Server 2012 or Windows Server 2012 R2. You can refer to our previous post on how to create

  • Windows Server 2012 or 2012 R2 Sysprep Image – Click here
  • Windows Server 2008 R2 – click here

Note:- Just create a virtual machine, do not run downloader.ps1 and installer.ps1. In this exercise, we are “NOT” setting up System Center deployment.

Default:-

  • VM Location = C:\VMs
  • Virtual Processor = 2
  • Computer name start with prefix = MS4U
  • Dynamic memory =

Startup –1024MB
Min – 512MB
Max – 2048MB
Buffer 20%

  • Virtual Switch = External
  • Assign static IP starting from 192.168.168.70
  • Gateway = 192.168.168.254
  • DNS = 192.168.168.201
  • Automatic start = nothing
  • Delay = 0
  • Automatic stop = Save
  • DVD = None
  • Additional 1 data disk =Yes
VM Name Processor Memory Data Disk
TestVM1 default default default
TestVM2 default Startup –1024MB
Min – 512MB
Max – 8192MB
Buffer 5%
Create 3 additional disk with each 50GB size
TestVM3 default Startup –2048MB
Min – 2048MB
Max – 2048MB
Buffer 20%
default
TestVM4 default default default

Modify the default variable.xml or just create a new variable.xml with just below information. Example:- Create 4 Windows Server 2012 R2 Virtual Machine

<?xml version="1.0" encoding="utf-8"?>
<Installer version="2.0">
  <Variable Name="RegisteredUser" Value="Lab" />
  <Variable Name="RegisteredOrganization" Value="MS4U Corporation" />
  <Variable Name="InstallerServiceAccount" Value="icglab\!Installer" />
  <Variable Name="InstallerServiceAccountPassword" Value="P@ssw0rd" />

  <VMs>
    <Count>4</Count>
    <Default>
      <Host>Localhost</Host>
      <VMFolder>C:\VMs</VMFolder>
      <VHDFolder>C:\VMs</VHDFolder>
      <VMName>
        <Prefix>MS4U</Prefix>
        <Sequence>1</Sequence>
      </VMName>
      <Processor>2</Processor>
      <Memory>
        <Startup>1024</Startup>
        <Minimum>512</Minimum>
        <Maximum>2048</Maximum>
        <Buffer>20</Buffer>
      </Memory>
      <NetworkAdapter>
        <VirtualSwitch>External</VirtualSwitch>
        <MAC>
          <Prefix>00:15:5D:65:01:</Prefix>
          <Sequence>4</Sequence>
        </MAC>
        <IP>
          <Prefix>192.168.168.</Prefix>
          <Sequence>70</Sequence>
          <Mask>24</Mask>
          <Gateway>192.168.168.254</Gateway>
          <DNS>192.168.168.201</DNS>
        </IP>
      </NetworkAdapter>
      <OSDisk>
        <Parent>C:\VHD\WS12R2D.vhdx</Parent>
        <Type>Copy</Type>
      </OSDisk>
      <DataDisks>
        <Count>1</Count>
        <Format>VHDX</Format>
        <Size>50</Size>
      </DataDisks>
      <DVD>False</DVD>
      <AutoStart>
        <Action>Nothing</Action>
        <Delay>0</Delay>
      </AutoStart>
      <JoinDomain>
        <Domain>icglab.local</Domain>
        <Credentials>
          <Domain>icglab.local</Domain>
          <Password>P@ssw0rd</Password>
          <Username>administrator</Username>
        </Credentials>
        <OrganizationalUnit>Computers</OrganizationalUnit>
      </JoinDomain>
      <AdministratorPassword>P@ssw0rd</AdministratorPassword>
    </Default>
    <VM Count="1">
      <VMName>TestVM1</VMName>
    </VM>
    <VM Count="2">
      <VMName>TestVM2</VMName>
      <Memory>
        <Startup>1024</Startup>
        <Minimum>512</Minimum>
        <Maximum>8192</Maximum>
        <Buffer>5</Buffer>
      </Memory>
      <DataDisks>
        <Count>3</Count>
        <Format>VHDX</Format>
        <Size>50</Size>
      </DataDisks>
    </VM>
    <VM Count="3">
      <VMName>TestVM3</VMName>
      <Memory>
        <Startup>2048</Startup>
        <Minimum>2048</Minimum>
        <Maximum>2048</Maximum>
        <Buffer>20</Buffer>
      </Memory>
    </VM>
    <VM Count="4">
      <VMName>TestVM4</VMName>
    </VM>
  </VMs>
</Installer>

Output when execute VMCreator.ps1:-

image

image

image

image

Above script will create:-

  • Generation 1 VM. To modify to generation 2 VM, on the default section, do add

<VMGeneration>2</VMGeneration>

  • If your base image is dynamic disk, then the target VM will be dynamic disk as well. By default, the script is using differencing disk.

<Parent>C:\VHD\WS12R2D.vhdx</Parent>
<Type>Copy</Type>

  • The <Count>4</Count> must match to the end value of VM Count :-
  • <VM Count="4">

Please feel free to modify the script according to your environment.

No comments:

Post a Comment