Using Task Sequence variables in a PowerShell script

Hi Again,

In my last entry I posted a script that uses the following line of code:

Running the above code during the build process (i.e. inside the Task Sequence) lets me interact with any Task Sequence variable. I can obtain the value of any variable in the Task Sequence by running $TSEnv.Value(“VariableName”) – for example:

This also works for custom variables:

We can also set the value of a variable by using the same method – adding =”value” at the end. For example:

In our environment we’ve used this for a range of things, combined with an MDT Web Service the possibilities are endless!

2 thoughts on “Using Task Sequence variables in a PowerShell script

  1. Bill Westrup

    no luck.
    Running this:
    “$TSEnv = New-Object -ComObject Microsoft.SMS.TSEnvironment”

    Produces this:
    “New-Object : Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed due to the
    following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
    At line:1 char:10
    + $TSEnv = New-Object -ComObject Microsoft.SMS.TSEnvironment
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException
    + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand”


Leave a Reply

Your email address will not be published. Required fields are marked *