This article explains how to use PowerShell to perform tasks within the Microsoft Deployment Toolkit.

Most of the tasks performed within the deployment workbench are really performed by PowerShell under the bonnet. So in theory a lot of the tasks you might perform in MDT can be automated. In order to use the MDT cmdlets, we need to import them into our PowerShell session; the Cmdlets are contained within a snapin. To access these cmdlets, we need to import them by using the command.

    Add-PSSnapIn Microsoft.BDD.PSSnapIn

After importing the snapin, we can see the cmdlets it contains by using the command Get-command -pssnapin microsoft.bdd.pssnapin 

In order to use most of these commands, we need to use another part of the MDT Pssnapin, the MDT Provider. By using the provider, PowerShell can create a drive which essentially maps to the MDT deployment share, allowing it to be managed via PowerShell.

To create a drive we need to run the PowerShell command New-PSDrive -Name DS005 -PSProvider mdtprovider -Root d:\DeploymentShare

Once this command is run, we can actually browse the MDT workbench structure as if it were a file structure. By running the command Set-location DS005: and Get-childitem or by using PowerShell aliasing commands CD DS005: and DIR you get the following results:

Once the PSdrive is setup, you can perform any MDT related task using the Cmdlets contained within the snapin and the native PowerShell cmdlets.

Below is a list of PowerShell commands used to perform commonly used tasks within MDT 2010.

Creating a MDT 2010 Database using PowerShell

Add-PSSnapIn Microsoft.BDD.PSSnapIn
New-PSDrive -Name DS005 -PSProvider mdtprovider -Root d:\DeploymentShare
New-MDTDatabase -SQLServer ‘yourservername’ -Database ‘MDTDB’ -SQLShare ‘lab$’ -Path ‘ds005:’

Importing drivers into the MDT Workbench from more than one location

The following commands create a new driver folder then take all the drivers from 2 different directories and adds them to the newly created folder.

New-item -Path “DS005:\Out-of-Box Drivers” -Enable “True” -Name “HP8540p” -Comments “Drivers for HP 8540p” -ItemType “folder” -Verbose

Import-MDTDriver -SourcePath “C:\drivers”,”C:\drivers2″ -Path “DS005:\Out-of-Box Drivers\HP8540p” –Verbose