Jump to content
Sign in to follow this  
hoopjunkie

Using SCCM WebServices and AutoIT

Recommended Posts

hoopjunkie

Trying to create a script to pull information from a well known SCCM(ConfigMgr 2007) web service.  Web Service works great however the script, not so much.  I have started with just a little script to find the computer information for a specific computer.  I believe if I can get this one working, using the other available functions should be a simple replacement.  However I continue to receive a -1 for reading the data from the XML file that is generated with this service.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.6.1
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------
#Include <_XMLDomWrapper.au3>
#include <Array.au3>

;~ ; Script Start - Add your code below here

$sSiteCode = "001"
$sCompName = "compname"
$sHostName = "http://hostname.com"

$datafile = "received.xml"

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("GET",$sHostName & "/sms_osd/sccm.asmx/SearchComputerByName?SearchString=" & $sCompName & "&SiteCode=" & $sSiteCode, False)


$oHTTP.Send()
$oReceived = $oHTTP.ResponseText
MsgBox(1, "text", $oReceived)
$oStatusCode = $oHTTP.Status

If $oStatusCode == 200 then
 $file = FileOpen("Received.xml", 2) ; The value of 2 overwrites the file if it already exists
 FileWrite($file, $oReceived)
 FileClose($file)
EndIf

If FileExists($datafile) Then

    $ret = _XMLFileOpen($datafile)

    MsgBox(1,"File Open", $ret)
        if $ret = 1 then
            MsgBox(0, "Open File Correctly?", "Yes")
        Else
            MsgBox(48, "Open File Correctly?", "NO")
            MsgBox(48,"File Open Error!!", @error)
        EndIf
    $sADSiteName = _XMLGetValue("Resource/ADSiteName")
    $sADSiteName2 = _XMLGetValue("/Resource/ADSiteName")
    $sName = _XMLGetValue("/Resource/Name")
    $sNetbiosName = _XMLGetValue("/Resource/NetbiosName")
    $sObsolete = _XMLGetValue("/Resource/Obsolete")
    $sOperatingSystemNameandVersion = _XMLGetValue("/Resource/OperatingSystemNameandVersion")
    $sResourceID = _XMLGetValue("/Resource/ResourceID")
    $sSMSUniqueIdentifier = _XMLGetValue("/Resource/SMSUniqueIdentifier")

;~          _ArrayDisplay($node)
        MsgBox(4096, $sADSiteName[0], $sADSiteName[1])
        MsgBox(4096, $sName[0], $sName[1])
        MsgBox(4096, $sNetbiosName[0], $sNetbiosName[1])
        MsgBox(4096, $sObsolete[0], $sObsolete[1])
        MsgBox(4096, $sOperatingSystemNameandVersion[0], $sOperatingSystemNameandVersion[1])
        MsgBox(4096, $sResourceID[0], $sResourceID[1])
        MsgBox(4096, $sSMSUniqueIdentifier[0], $sSMSUniqueIdentifier[1])
        MsgBox(4096, "Error", _XMLError ())
    EndIf

XML that is generated by using IE to the webservice

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfResource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://maikkoster.com/Deployment">
  <Resource>
    <ADSiteName>SiteName</ADSiteName>
    <Name>CompName</Name>
    <NetbiosName>NetBiosName</NetbiosName>
    <Obsolete>false</Obsolete>
    <OperatingSystemNameandVersion>Microsoft Windows NT Workstation 6.1</OperatingSystemNameandVersion>
    <ResourceID>164029</ResourceID>
    <SMSUniqueIdentifier>GUID:BA22409B-DAC9-42FC-B538-3BBA1CC79F33</SMSUniqueIdentifier>
  </Resource>
</ArrayOfResource>

Share this post


Link to post
Share on other sites
JLogan3o13

Hi, hoopjunkie, welcome to the forum. You might check out the SCCM script in my signature. It has a number of functions that show connecting directly to an SCCM 2007 db and querying for information, as well as adding to and removing from collections. Might point you in the right direction.


√-1 2^3 ∑ π, and it was delicious!

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.