WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: therkilt on July 25, 2013, 07:26:10 AM

Title: SCCM OSD variables
Post by: therkilt on July 25, 2013, 07:26:10 AM
I'm trying to figure out how to do the following VBS code in WinBatch
Set oTSEnv = CreateObject("Microsoft.SMS.TSEnvironment")
For Each oVar In oTSEnv.GetVariables
WScript.Echo oVar & "=" & oTSEnv(oVar)
Next

So Far I have it getting the defined variable names, however I have not been able to get the variable values yet:
Code (winbatch) Select

Variables = ``
oTSEnv = ObjectCreate("Microsoft.SMS.TSEnvironment")
ForEach objInstance In oTSEnv.GetVariables
Variables = StrCat(Variables,objInstance,` = `,`|`)
Next
Pause(`Variables`,Variables)


Even if I know a specific variable I want to check I haven't been able to read the value directly using Winbatch yet.

Any help would be appreciated, I tried searching the forum and support site and have been unable to find any previous mention of SCCM or OSD or Microsoft.SMS.TSEnvironment.

Thanks.
Title: Re: SCCM OSD variables
Post by: Deana on July 25, 2013, 08:42:39 AM
Maybe try objInstance.Value ?
Title: Re: SCCM OSD variables
Post by: therkilt on July 25, 2013, 12:30:25 PM
Thanks, I finally got it.
Code (winbatch) Select

ProgressUI = ObjectCreate("Microsoft.SMS.TsProgressUI")
ProgressUI.CloseProgressDialog;Close the SCCM task sequence bar while displaying an interface (it will automatically start when this script finishes)
ObjectClose(ProgressUI)

Variables = ``
oTSEnv = ObjectCreate("Microsoft.SMS.TSEnvironment")
ForEach objInstance In oTSEnv.GetVariables
Variables = StrCat(Variables,objInstance,` = `,oTSEnv.Value(objInstance),`|`);Get all defined variables
Next
Pause(`All defined TS Variables`,Variables)
Pause(`_SMSTSLogPath`,oTSEnv.Value("_SMSTSLogPath"));Get a single Variable
ObjectClose(oTSEnv)
Title: Re: SCCM OSD variables
Post by: Deana on July 25, 2013, 12:45:08 PM
Great! Thanks for sharing the solution.
Title: Re: SCCM OSD variables
Post by: therkilt on July 25, 2013, 01:38:18 PM
Here is an update with more useful procedures
Code (winbatch) Select

ProgressUI = ObjectCreate("Microsoft.SMS.TsProgressUI")
ProgressUI.CloseProgressDialog;Close the SCCM task sequence bar while displaying an interface (it will automatically start when this script finishes)
ObjectClose(ProgressUI)

ErrorMode(@NOTIFY)
Variables = ``
oTSEnv = ObjectCreate("Microsoft.SMS.TSEnvironment")
oTSEnv.Value("TestVariableTT") = ``;Deletes a variable
if oTSEnv.Value("TestVariableTT") == `` then Message(`TestVariableTT`,`Is not in the TS yet`);Verify a variable is not defined
oTSEnv.Value("TestVariableTT") = `Test_1`;Sets a variable
if oTSEnv.Value("TestVariableTT") <> `` then Message(`TestVariableTT`,`Is now in the TS`);Verify a variable is defined
ForEach objInstance In oTSEnv.GetVariables
Variables = StrCat(Variables,objInstance,` = `,oTSEnv.Value(objInstance),`|`);Get all defined variables and thier values
Next
Pause(``,StrCat(`_SMSTSLogPath = `,oTSEnv.Value("_SMSTSLogPath"),@CRLF,`TestVariableTT = `,oTSEnv.Value("TestVariableTT")));Get specific values
ObjectClose(oTSEnv)
AskItemList(`All defined TS Variables`,Variables,`|`,@SORTED,@EXTENDED,@FALSE)
Title: Re: SCCM OSD variables
Post by: Orionbelt on August 13, 2013, 12:24:58 PM
I know this is old post. but i am running same script under WinPE x86 image. I am getting 1727: COM:INVALID CLASS STRING.

I am running this exe with unattended.xml file in Winpe.wim file.