mortalwombat

Pull variable from MDT

5 posts in this topic

#1 ·  Posted

I am trying to use a variable from MDT in my AutoIT script. The only help I have been able to find on this is from this thread.  In MDT, my variable is named TermID. When I try this code, I would expect it to pre-populate the input box with the value of TermID from MDT.

$Var = "TermID"
$SCCM = ObjCreate("Microsoft.SMS.TSEnvironment")
$VarResult = $SCCM.Value($Var)
$termID = InputBox("TermID", "Enter the Terminal ID for this MDC", $VarResult, "", "", "", "100", "100")

However, when I run the script I get the error "Variable must be of type "Object"." References the third line. I am fairly new to scripting so I'm not too sure what that means or what I'm doing wrong. Any help would be greatly appreciated. 

Share this post


Link to post
Share on other sites



#2 ·  Posted

The following requirements apply if you want to access objects on remote computers:


  • The user running the script must have the appropriate permissions.
  • The Object on the remote computer must support DCOM (Distributed COM)
  • The remote computer must have 'Remote Registry Service' and 'File and Printer sharing' services running.

 

 

Are all of these satisfied?

Share this post


Link to post
Share on other sites

#3 ·  Posted

I'm not running it on a remote computer. I am using a task sequence that defines a task sequence variable, then launches the autoit exe. Or are you saying the deployment server needs to meet those requirements?

Share this post


Link to post
Share on other sites

#4 ·  Posted

I think I may have just found an alternate way to approach this. MDT writes variables to a temporary .dat file that is in XML format. The XML looks like this: 

<?XML Version="1.0"?>
<MediaVarList Version="4.00.4345.0000">
  <var name="TERMID">
    <![CDATA[SPMXY]]>
  </var>
</MediaVarList>

I essentially need to get the value of the TERM ID, which in this case should be SPMXY. 

Share this post


Link to post
Share on other sites

#5 ·  Posted

OK, I worked it out! So here's a recap for anyone who may follow behind me:

I found that MDT writes a it's variables to C:\MININT\SMSOSD\OSDLOGS\VARIABLES.DAT while it's running, then deletes it when it's finished. The .dat file is in XML format, so I was able to query it. The XML format looks like this: 

<?XML Version="1.0"?>
<MediaVarList Version="4.00.4345.0000">
  <var name="TERMID"><![CDATA[123]]></var>
  <var name="VARIABLE1"><![CDATA[ABC]]></var>
  <var name="VARIABLE2"><![CDATA[XYZ]]></var>
</MediaVarList>

The code that I used to query the different variables looks like this:

$datfile = "C:\MININT\SMSOSD\OSDLOGS\VARIABLES.DAT"

If FileExists($datfile) Then ;check to see if file exists. If so, load the file
    ConsoleWrite("File Exists - Loading " & $datfile)
    Local $oXML = ObjCreate("Microsoft.XMLDOM")
    $oXML.load($datfile)


    For $oConfig in $oXML.selectNodes("//var") ;select each of the var nodes in a loop
        $sAttribute = $oConfig.getAttribute('name') ;for each var, get the 'name' attribute
            If $sAttribute == "TERMID" Then ;if the 'name atribute is 'TERMID', write that to a variable and echo the termID in the console
                $myTermID = $oConfig.text
                ConsoleWrite($myTermID & @CRLF)
            ElseIf $sAttribute == "Variable1" Then ;if the 'name atribute is 'Variable1', write that to a variable and echo the variable in the console
                $myVariable1 = $oConfig.text
                ConsoleWrite("Variable1 => " & $myVariable1 & @CRLF)
            ElseIf $sAttribute == "Variable2" Then ;if the 'name atribute is 'Variable2', write that to a variable and echo the variable in the console
                $myVariable2 = $oConfig.text
                ConsoleWrite("Variable 2 => " & $myVariable2 & @CRLF)
            EndIf

    Next
Else
    ConsoleWrite("Dat file does not exits.") ;If file does not exist, echo error to console
EndIf

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now