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:
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.
Maybe try objInstance.Value ?
Thanks, I finally got it.
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)
Great! Thanks for sharing the solution.
Here is an update with more useful procedures
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)
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.