Jump to content

Microsoft System Center Configuration Manager


Recommended Posts

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.

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • 4 weeks later...

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...