hemichallenger Posted June 21, 2014 Share Posted June 21, 2014 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 More sharing options...
Moderators JLogan3o13 Posted June 23, 2014 Moderators Share Posted June 23, 2014 (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 June 23, 2014 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 More sharing options...
hemichallenger Posted July 16, 2014 Author Share Posted July 16, 2014 (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 July 17, 2014 by hemichallenger Link to comment Share on other sites More sharing options...
kylomas Posted July 17, 2014 Share Posted July 17, 2014 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 Link to comment Share on other sites More sharing options...
hemichallenger Posted July 17, 2014 Author Share Posted July 17, 2014 (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 July 17, 2014 by hemichallenger Link to comment Share on other sites More sharing options...
hemichallenger Posted July 17, 2014 Author Share Posted July 17, 2014 (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 July 22, 2014 by hemichallenger Link to comment Share on other sites More sharing options...
hemichallenger Posted July 22, 2014 Author Share Posted July 22, 2014 Is there a way you can search specific parent collection ID's only then get the sub collections as a results? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now