Creating the MDT 2012/2013 Deployment share using PowerShell

Here is a quick PowerShell example that shows you how to create a deployment share using PowerShell.

For those of you that are MDT savvy, you know that MDT has a View Script button option that allow you to see what PowerShell commands that MDT executes. Unfortunately, MDT sometimes lies to you, and the workbench will actually do more than the View Script button tells you.

Sample Script

Here is a script to create a MDT deployment share

If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
    [Security.Principal.WindowsBuiltInRole] "Administrator"))
    Write-Warning "Oupps, you need to run this script from an elevated PowerShell prompt!`nPlease start the PowerShell prompt as an Administrator and re-run the script."
    Write-Warning "Aborting script..."

# Validation OK, load the MDT SnapIn
Add-PSSnapIn Microsoft.BDD.PSSnapIn -ErrorAction SilentlyContinue

# Create MDT deployment share
$MDTServer = (get-wmiobject win32_computersystem).Name
$InstallDrive = "C:"
New-Item -Path $InstallDriveMDTProduction -ItemType directory
New-PSDrive -Name "DS001" -PSProvider "MDTProvider" -Root "$InstallDriveMDTProduction" -Description "MDT Production" -NetworkPath "$MDTServerMDTProduction$" | add-MDTPersistentDrive
New-SmbShare -Name MDTProduction$ -Path "$InstallDriveMDTProduction" -ChangeAccess EVERYONE

# Create optional MDT Media content
New-Item -Path $InstallDriveMEDIA001 -ItemType directory
New-PSDrive -Name "DS002" -PSProvider MDTProvider -Root "$InstallDriveMDTProduction"
New-Item -Path "DS002:Media" -enable "True" -Name "MEDIA001" -Comments "" -Root "$InstallDriveMEDIA001" -SelectionProfile "Nothing" -SupportX86 "False" -SupportX64 "True" -GenerateISO "False" -ISOName "LiteTouchMedia.iso" -Force -Verbose
New-PSDrive -Name "MEDIA001" -PSProvider "MDTProvider" -Root "$InstallDriveMEDIA001ContentDeploy" -Description "MDT Production Media" -Force -Verbose

# Update the MDT Media (and another round of creation because of a bug in MDT internal processing)
Update-MDTMedia -path "DS002:MediaMEDIA001" -Verbose
Remove-Item -path "DS002:MediaMEDIA001" -force -verbose
New-Item -path "DS002:Media" -enable "True" -Name "MEDIA001" -Comments "" -Root "$InstallDriveMEDIA001" -SelectionProfile "Everything" -SupportX86 "False" -SupportX64 "True" -GenerateISO "False" -ISOName "LiteTouchMedia.iso" -Verbose -Force
New-PSDrive -Name "MEDIA001" -PSProvider "MDTProvider" -Root "$InstallDriveMEDIA001ContentDeploy" -Description "MDT Production Media" -Force -Verbose

Happy deployment

/ Johan

About the author

Johan Arwidmark

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments