Hey all. What I'm trying to accomplish is a basic script that will query a server for 4 services. If the service is installed, it will query the service for certain properties. I'm basically doing something like:
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE DisplayName='Automatic Updates' or DisplayName='DNS Client' or DisplayName='Something Else' or Displayname='Yet Another Service'")
I have no problem iterating though the collection to get the properties that I want if the service is installed. What I'm having difficulties with is comprehending a way to see what services of the 4 I am attempting to add to the collection actually made it to the collection. So if I query for 4 and the count ends up being 2, how can I tell which of the 4 didn't get added to the collection? Sure I can assume that if A and C exist, then B and D aren't installed but I'm trying to write this info to a CSV and would like to write "Service B does not exist" to the file rather than not having any notation at all for that service and using a For/Next to go through the collection won't tell me what's not there.
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE DisplayName='Automatic Updates' or DisplayName='DNS Client' or DisplayName='Something Else' or Displayname='Yet Another Service'")
I have no problem iterating though the collection to get the properties that I want if the service is installed. What I'm having difficulties with is comprehending a way to see what services of the 4 I am attempting to add to the collection actually made it to the collection. So if I query for 4 and the count ends up being 2, how can I tell which of the 4 didn't get added to the collection? Sure I can assume that if A and C exist, then B and D aren't installed but I'm trying to write this info to a CSV and would like to write "Service B does not exist" to the file rather than not having any notation at all for that service and using a For/Next to go through the collection won't tell me what's not there.