It seems like an understatement to just say that MDT 2010 now supports PowerShell to automate Deployment Workbench administrative tasks. Really, Deployment Workbench has been completely re-architected – all operations you perform through the UI are turned into PowerShell commands that are executed by the PowerShell engine, providers, and cmdlets. As a result, a significant portion of the Deployment Workbench has been rewritten – this is definitely no small change.
Behind the scenes, there are a few pieces to make this work:
All of these are contained in a single PowerShell snap-in, so before you can use the PowerShell provider yourself you need to load this snap-in. This is pretty easy to do with a single PowerShell command:
Add-PSSnapIn Microsoft.BDD.PSSnapIn
First let’s talk more about the PowerShell provider. In order to use it, you need to create a “PowerShell drive” (see http://technet.microsoft.com/en-us/library/dd315335.aspx for details). This is like mapping a network drive: creating a logical “drive” that is used to navigate through the logical contents of a deployment share. The MDT PowerShell provider doesn’t create any drives by default, so you need to create one or more. This can be done in one of two ways. First, the manual way:
New-PSDrive -Name MyDrive -PSProvider MDTProvider -Root \\server\DeploymentShare$
In this case, the logical drive name assigned will be “MyDrive” (you could use whatever value you like), it is created using the MDT PowerShell provider which is called “MDTProvider” (always), and it points to the deployment share at \\server\DeploymentShare$ . Once the drive is created, you can navigate through it and look at the contents.
But first, let’s talk about the second way of creating MDT drives. The Deployment Workbench keeps track of all deployment shares that you opened through the UI. To get the same ones through PowerShell, you can execute a single cmdlet:
Restore-MDTPersistentDrive
You’ll see the names and paths for all restored drives, e.g. “DS001” for the first deployment share \\server\DeploymentShare$ .
OK, so now let’s assume you have at least one PowerShell drive, “MyDrive”. To see the top-level folders, try this:
Want to see all the drivers? Try:
dir 'MyDrive:\Out-of-Box Drivers'
Want to create a new folder? Try:
mkdir ‘MyDrive:\Out-of-Box Drivers\New Folder’
Want to see all the deployment share properties? Try:
Get-ItemProperty MyDrive:
Want to update the deployment share (generating boot images)? Try:
Update-MDTDeploymentShare -Path MyDrive:
You can use pretty much any of the standard PowerShell cmdlets for drive providers:
What if you want to create new applications, import drivers, create task sequences, update the deployment share, etc.? That’s where the other MDT cmdlets come in:
The Deployment Workbench does all of its work using the cmdlets listed above. In many cases, the wizards will show you these PowerShell commands, so that you can copy and paste them into your own PowerShell scripts.
With any luck, we’ll post more PowerShell script samples in the coming months.