0

I have a list of computer names stored in an vbscript array and need check whether these have an object in SCCM or not.

I have tried using a query similar to: set accounts = sQbemServices.ExecQuery("select * FROM SMS_R_System WHERE name = '" & testForName & "'") to look through SCCM. This works ok as long as the computer names are valid, but once it reaches an invalid name, it seems to stop. I have tried outputting the error number, but this always returns a '0' and checking if the result is null, but this doesn't work.

Is this the best way to check that a computer object exists and, if so, can anyone tell me what I'm doing wrong please? If not, any pointers would be much appreciated.

user1384247
  • 1
  • 1
  • 1

1 Answers1

0

SWbemServices.ExecQuery normally returns a SWbemObjectSet. If your query finds a valid computer then accounts.Count should be 1 or more, otherwise 0. Eg:

If (accounts.Count > 0) Then 
    WScript.Echo "Found Computer in SCCM"
Else
    WScript.Echo "Computer is not in SCCM"
End If

For more information about SWbemServices:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa393866(v=vs.85).aspx

Gareth Oakley
  • 1,020
  • 1
  • 12
  • 34