LTI/ZTI PowerShell: Outputting Transcript from PowerShell Console

While testing a Lite-Touch deployment, I had an issue with a PowerShell script running in an application package. The error flashed by on the console screen so fast that I could not read it. To top that off, the log file reported the execution as a success. I had to run the deployment 3 times to capture this screen shot.

Transcript - Error

Why run it as an application instead of a Run PowerShell Script? Well the script imports GPO’s and I have a manifest and other files that work with it, so it makes sense to create an application package and keep everything together. The issue is that running the script in this manner takes away the advanced logging features that a Run PowerShell Script task sequence step provides.

I then remembered that there was a PowerShell command that I could employ to help here. It’s called Start-Transcript and its an easy one to use. Here’s an example:

Begin {
 Import-Module GroupPolicy
 Start-Transcript C:\Temp\Transcript.txt
Process {
 Import-GPO -BackupGpoName 'Default Domain Policy' -TargetName 'Default Domain Policy' -Path (Get-Location)
End {

After running the script, you’re left with a text output of your session.

Transcript - Log

This handy trick helped me track down the issue and get my deployment back on track. In the end my Import GPO issue was quite easy to fix:

Begin {
 Import-Module GroupPolicy
 $AppPath = $PWD.ProviderPath
Process {
 Import-GPO -BackupGpoName 'Default Domain Policy' -TargetName 'Default Domain Policy' -Path $AppPath
End {}

About Andrew Barnes

A Scripting and Deployment Specialist.
This entry was posted in MDT 2010, MDT 2012, PowerShell, SCCM, Scripting and tagged , , , . Bookmark the permalink.

6 Responses to LTI/ZTI PowerShell: Outputting Transcript from PowerShell Console

  1. Marcus says:

    Hey Andrew,
    What “Quiet install command:” do you use when running PowerShell scripts as an application?

    Do you have to modify the “Set-ExecutionPolicy” before you run your own scripts?

    Great post keep up the good work!


  2. Dale Isaak says:

    I have been using batch files to run my application installs but I have decided to use PowerShell going forward. I call my my install script like this:
    cscript.exe //nologo %scriptroot%\ZTIPowershell.wsf test.ps1
    That way I get the automatic logging from write-host, write-debug and write-error.

    I had to modify ZTIPowershell.wsf a bit to make this work:
    ‘ if the scriptname variable is not initialized
    if oEnvironment.Item(“ScriptName”) = “” then
    ‘ set it to the scriptname supplied on the command line
    oEnvironment.Item(“ScriptName”) = WScript.Arguments.Item(0)

    ‘ Set the parameters variable to the rest of the parameters supplied on the command line
    x = 1
    do until x >= WScript.Arguments.count
    parameter = WScript.Arguments.Item(x)
    ‘ if there is a space in the parameter surround it with quotes
    if instr(parameter, ” “) > 0 then parameter = chr(34) & Parameter & chr(34)

    ‘ add the parameter to the parameters variable
    parameters = parameters & ” ” & parameter
    x = x + 1

    ‘ remove extra spaces
    oEnvironment.Item(“Parameters”) = trim(parameters)
    end if

    ‘ Now run the PowerShell host
    sCmd = “””” & sModules & “\Microsoft.BDD.TaskSequenceModule\Microsoft.BDD.TaskSequencePSHost.exe”” ” & oEnvironment.Item(“ScriptName”)
    oLogging.CreateEntry “About to run: ” & sCmd, LogTypeInfo
    iRetVal = oShell.Run(sCmd, 0, true)

    ‘ Reset the variables because with my changes, if they aren’t, they won’t get updated when this script is called again using the Run PowerShell task.
    oEnvironment.Item(“ScriptName”) = “”
    oEnvironment.Item(“Parameters”) = “”

    If you are interested, I have written a script to set up the MDT variables in a PowerShell session so the scripts can be tested outside of MDT. It uses ZTIGather.wsf to read the local and customsettings.ini variables and then creates them in tsenv:


  3. Ryan says:

    Can You please post your modified ZTIPowershell.wsf? I am currently using MDT 2013 and have a powershell script to install some items and would like any errors displayed from the powershell install (which is called from Install Applications) to be shown in the Deployment Summary. Thanks!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your 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