Performing MDT tasks using Powershell

If you have ever performed a task using MDT 2010 you may have noticed that you have the option to view the script at the end of a wizard.

This script is a Windows Powershell script. 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.

Getting started with the MDT 2010 PowerShell Cmdlets

In order to use the MDT cmdlets, we need to import them into our Powershell, the Cmdlets are contained within a snapin. To access these cmdlets, we need to import them by specifying 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 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 are 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

If your like me, your drivers are most likely not stored in one big directory. When importing drivers within the workbench you are only able to select from one location at a time. By using Powershell, we are able to import as many drivers, from as many locations all in one command, instead of performing multiple GUI entries.

The following command creates a new driver folder then takes 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 DriversHP8540p” -Verbose





 

One Response to Performing MDT tasks using Powershell

  1. There seems to be a shortage of commands with that Snapin. At least we have the PSDrive that we can use to document our MDT environments.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: