PowerShell Scripts in MDT

When a Run PowerShell Script task sequence step runs a Windows PowerShell script, the step automatically loads the Microsoft.BDD.TaskSequenceModule module prior to running the script. The Microsoft.BDD.TaskSequenceModule module is responsible for creating the TSENV: and TSENVLIST: Windows PowerShell drives.

It may be needed to change execution policy to:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

In addition, it is recommended that your script load the ZTIUtility.psm1 module at the beginning of your script by adding the following line to the beginning of your script:

Import-Module .\ZTIUtility.psm1

(located at /Tools/Modules/ZTIUtility/ in deployment share).

TSENV: This drive is a list of all the task sequence variables and their current values. You can access this drive as you would any other Windows drive.
TSENVLIST: This drive lists all the task sequence variables and their current values as an array.

Working with PS drives

This command displays the contents of the ScriptRoot task sequence variable to the Windows PowerShell console.

Write-Host $tsenv:ScriptRoot

This command sets the $packages Windows PowerShell variable to the current value of the PACKAGES task sequence variable.

$packages = $tsenvlist:PACKAGES

This command sets the value of the PACKAGES task sequence variable to „XXX00001:Program“,„XXX00002:Program“.

$tsenvlist:PACKAGES = @("XXX00001:Program","XXX00002:Program")


By default, the output from your Windows PowerShell scripts is written to BDD.LOG. Table lists the message types that appear in the BDD.LOG file and how those types of messages are generated by your script.

Message type Generated by the following cmdlets
Informational Any cmdlets that write to the Windows PowerShell console, such as Write-Host or Out-Host
Warning Write-Warning cmdlet
Error Write-Error cmdlet

The progress for your Windows PowerShell script is shown in the task sequence progress UI and is displayed as follows:

  • Progress is shown as a percentage of total completion for the current script and any messages that are being displayed.
  • Progress is updated using the standard Write-Progress cmdlet.

Unlike some of the other scripts in MDT, a separate log file is not generated for the task sequence step running the Windows PowerShell script. Logging is only performed in the BDD.LOG file.

Pause execution of script for debugging

To pause execution for example we can show dialog window:

[System.Windows.Forms.MessageBox]::Show("Click to continue...")


windows/mdt/powershell-scripting.txt · Poslední úprava: 23.08.2016 10:35 autor: vm

Nástroje pro stránku