With my PowerCLI function New-MDTVM, you can easily deploy VMware virtual machines (VMs) with the Microsoft Deployment Toolkit (MDT).

If you are managing Windows servers, chances are you have a mix of physical and virtual servers in your data center. While VMware provides a method to create VMs from templates to simplify server deployments, this method obviously does not work for deploying physical servers. Fortunately, you can use MDT to deploy a physical or virtual server, which provides one solution for configuring on-premises server deployment tasks.

For new servers to use MDT, they need to boot to Windows PE using the preboot execution environment (PXE). We most commonly do this with Windows Deployment Services (WDS) or by booting directly to CD/ISO Lite Touch media, which circumvents WDS. For deploying new VMs, I prefer to attach the Lite Touch ISO file to a VM. Using this method, I do not have to depend on PXE. In addition, I can automate creating a new VMware virtual machine by just running a PowerCLI cmdlet.

Configuring MDT

One of the exceptional features of MDT is that you can automate the wizard to the point where there is no need for user interaction. This is ideal for server deployments because depending on the size of your environment, automation is essential for reducing overhead. You can easily deploy multiple VMs simultaneously. I will not elaborate on this process as there are many tutorials online, but I highly recommend you take this approach.

Copy the Lite Touch ISO to a data store with PowerCLI

After setting up and configuring MDT to automate the deployment wizard, the next step is to copy over the Lite Touch ISO to a data store in your vSphere environment.

To copy the ISO to a data store, we can use the Copy-DataStoreItem cmdlet in PowerCLI. In the example below we are copying the Lite Touch ISO file from the "MDTServer" MDT share to a data store called "testvmstore." Note that connecting to vCenter with PowerCLI creates a PS drive (vmstore) that provides access to all data stores via the VMware data store PowerShell provider.

Copy-DatastoreItem -Item '\\MDTServer\MDTShare$\Boot\LiteTouchPE_x64.iso\' ‑Destination 'vmstore:\testvmstore\INSTALL_MEDIA\LiteTouchPE_x64.iso'

Create and deploy a new virtual machine with PowerCLI

Now that we've copied the Lite Touch ISO, we can create a new VM with PowerCLI. We can then attach the ISO to the new VM, which will boot to a CD by default before the hard drive. Attaching the ISO to the virtual CD drive and starting the VM is all we need to begin the imaging process.

I created a simple function for this, New-MDTVM, to automate the attachment and detachment of the Lite Touch ISO. To do this, the function uses the PowerCLI cmdlet Set-CDDrive as well as the New-VM cmdlet to create the new VMware virtual machine in vSphere.

The Set-CDDrive cmdlet specifies the data store location of the Lite Touch ISO with the -IsoPath parameter and ensures the ISO is attached upon boot with -StartConnected:$true. Notice that with New-VM, you can set many features of the VM, such as guest OS, VMhost, disk size, memory, and network.

function New-MDTVM {

    [string]$CPU = '2',
    [string]$Memory = '4',
    [string]$DiskSpace = '40',
    [string]$DataStore = 'vmstore',
    [string]$NetworkName = 'VM Network',
    [string]$LiteTouchPath = 'InstallMedia\LiteTouchPE_x64.iso',
    [string]$GuestOS = 'windows8Server64Guest',
    [string]$VMHost = 'devhost',
    [string]$VCenter = ‘vcenter’

    Connect-VIServer $VCenter 
    New-VM -Name $ComputerName -GuestId $GuestOS -VMHost $VMHost -Version v11 -DiskGB $DiskSpace -Datastore $Datastore -MemoryGB $Memory -NumCpu $CPU -NetworkName $NetworkName -CD 
    Get-VM -Name $ComputerName | Get-CDDrive | Set-CDDrive -IsoPath "[$Datastore] $LiteTouchPath" -Confirm:$false -StartConnected:$true 
    Start-VM -VM $ComputerName -Confirm:$False 
    Start-Sleep -Seconds 60
    Get-CDDrive -VM $ComputerName | Set-CDDrive -NoMedia -Confirm:$False

New-MDTVM function example

In this example, I am going to create a new VM called "testvm," specifying the Lite Touch ISO location, memory amount, computer name, and vCenter hostname. Note the other parameters I will leave as their default values specified in the function.

PS> New-MDTVM -Computername testvm -Memory 8 ‑LiteTouchPath 'INSTALL_MEDIA\LiteTouchPE_x64.iso' -VCenter vcenter

If we open the VM console after running New-MDTVM, we see that MDT has begun the imaging process and is installing the operating system.

Subscribe to 4sysops newsletter!

Deploying an OS with the MDT

Deploying an OS with the MDT

  1. Avatar
    Leos Marek (Rank 4) 6 years ago

    Hi Dan,

    why not simply use standard vSphere approach and deploy VMs from previously build/customized golden image and customizing it via OS Customization manager?

    Seems much more simpler than this.

    Whats the difference?


    • Avatar
      Joe Bembry 6 years ago

      Hey Leos,

      The short answer is that MDT allows for more customization to your golden images. I don’t think the idea for this is the deployment of golden images, but rather the automatic creation of fully patched golden images that you can use for your vsphere templates. The MDT approach also allows for automation of all the OS features and additional software, etc to be included. We use a similar approach via Hyper-V.


  2. Avatar
    Leos Marek (Rank 4) 6 years ago


  3. Avatar

    Nice post, Dan!

    Did you try this in an Active Directory environment? If so, how have you solve the domain join?
    Offline via file? I meet the situation that I can’t login because firewall ports are closed …

    • Avatar
      Jesse Geron 4 years ago

      If using MDT, joining the domain is just a standard step in the task sequence. Nothing out of the ordinary there.

Leave a reply

Your email address will not be published. Required fields are marked *


© 4sysops 2006 - 2023


Please ask IT administration questions in the forums. Any other messages are welcome.


Log in with your credentials


Forgot your details?

Create Account