Hi Again,
In my last entry I posted a script that uses the following line of code:
1 |
$TSEnv = New-Object -ComObject Microsoft.SMS.TSEnvironment |
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:
1 2 3 |
$DeployRoot = $TSEnv.Value("DeployRoot") $OSDComputerName = $TSEnv.Value("OSDComputerName") $MachineObjectOU = $TSEnv.Value("MachineObjectOU") |
This also works for custom variables:
1 |
$JohnsCustomVariable = $TSEnv.Value("TheVariableWeSetUpEarlier") |
We can also set the value of a variable by using the same method – adding =”value” at the end. For example:
1 |
$TSEnv.Value("MachineObjectOU") = "OU=Inbuild,DC=Domain,DC=Net" |
In our environment we’ve used this for a range of things, combined with an MDT Web Service the possibilities are endless!
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”
Hi Bill, The code needs to be run from the MDT Task Sequence, it wont work out side of it. Hope that helps.