Sign in to follow this  
Followers 0
hemichallenger

Microsoft System Center Configuration Manager

7 posts in this topic

Not sure how to query SCCM. What I like to do is enter a computer name and MAC address, then it query SCCM for both , if the computer name or MAC is in a collection ID message what collection name its in if it not just message it not in a collection. Also check if the computer name was setup with a different MAC address or if the MAC address was setup with a different computer name.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi, hemichallenger. There is an SCCM UDF in the Examples Forum that you can look at. It is for 2007, and I have not had a chance to update it yet, but the db calls should be the same.

Edited by JLogan3o13

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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I did check out the script and have a issue. The script works fine and gets the information when searching but if the $machine isn't in sccm it does nothing and doesnt prompt the MsgBox(64, "test", "Not in SCCM").

Global $machine

Func _Search()
    Local $strComputer = GUICtrlRead ($Input1)
    $oLocator = ObjCreate("WbemScripting.SWbemLocator")
    $oSMS = $oLocator.ConnectServer($sServer, "root\sms\site_" & $SCode)

    $oResults = $oSMS.ExecQuery("SELECT * FROM SMS_R_System WHERE Name = '" & $strComputer & "'")
    For $element In $oResults
    $machine = $element.ResourceID
    $mac = $element.MacAddresses(0)

    If StringLen($machine) = Null Then
        MsgBox(64, "test", "Not in SCCM")
        Else
        MsgBox(0, "DoubleCheck", $strComputer & " with resourceID " & $machine & " is in SCCM so advertise it " & $mac & " Macaddress")
EndIf
Next
EndFunc

And I tried this and it didn't work either.

If StringLen($machine) < 1 Then

Or

If StringLen($machine) = True Then
MsgBox(0, "DoubleCheck", $strComputer & " with resourceID " & $machine & " is in SCCM so advertise it " & $mac & " Macaddress")
Else
MsgBox(64, "test", "Not in SCCM")
Edited by hemichallenger

Share this post


Link to post
Share on other sites

Try this...

if $machine = '' then

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I change it and still doesnt work.  Not sure what else I could do. In powershell it works fine with $Null.

$resID = Get-WmiObject -computername $SCCMServer -query "select resourceID from sms_r_system where name like `'$computername`'" -Namespace "root\sms\site_$sitename" $computerID = $resID.ResourceID 
if ($resID.ResourceId -eq $null) {"Not in SCCM"} 
else
Edited by hemichallenger

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

The placement of Next messed it up. But i got it working, Another questing with sccm in your script. How would you filter and search specific sub collections in a parent collectionID?

Func _SearchSubCollection()
Local $strComputer = GUICtrlRead ($Input1)

$parentcollID = "00000001; 00000002; 00000003"


    $oLocator = ObjCreate("WbemScripting.SWbemLocator")
    $oSMS = $oLocator.ConnectServer($sServer, "root\sms\site_" & $SCode)
    $SWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
    $SWbemServices = $SWbemLocator.ConnectServer($sServer,"root\SMS\site_" & $SCode)
    $oResults = $oSMS.ExecQuery("SELECT * FROM SMS_R_System WHERE Name = '" & $strComputer & "'")
    For $element In $oResults
    $machine = $element.ResourceID
Next
If StringLen($machine) < 1 Then
        MsgBox(0, "SCCM Console", "Could not retrieve computer [" & StringUpper($strComputer) & "] from SCCM.")
        $machine = ""
Else
        $strQuery = "select * from SMS_CollectionMember_a where ResourceID='" & $machine &"'"
        $aCollections = $SWbemServices.ExecQuery($strQuery)
            For $element in $aCollections
                $Collectionfound = $SWbemServices.Get("SMS_Collection='" & $element.CollectionID & "'" )
        MsgBox(0,"test", "collection " & $Collectionfound.name)
Next
EndIf
EndFunc

This script works but it pulls all the computers Collections. How could it be filtered to check only the parent collection ID $parentcollID?

Edited by hemichallenger

Share this post


Link to post
Share on other sites

Is there a way you can search specific parent collection ID's only then get the sub collections as a results?

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  
Followers 0