I need to get a list of all members of the local Administrators group on all servers in our environment. I then need to take that list and get the SID for each of those values.
These groups can contain local and domain accounts as well as local and foreign (trusted) domain groups (any combination).
I mashed some scripts together (below). Basically it checks for the "Administrators" group then parses through the list giving me the SID of the group members that are also groups.
My problem is this: the objUser variable returns the group name with no domain or server info. So when my WMI call goes out it finds anything by that particular name on any server or domain and returns the SID info for all of them.
Example: If a member is "domain1\domain admins" my script tells WMI to return the SID of anyone it finds named "Domain admins." The result in my case is 16 different SID's from 16 different domains.
Two questions:
1. How do I include domain information? I thought of the objWMIService.get but wasn't sure if that would be better or worse.
2. Is there a much better way to get the desired results?
Thanks!
-----------------
strComputer = InputBox("Server Name
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colGroups = GetObject("WinNT://" & strComputer & "")
colGroups.Filter = Array("group")
For Each objGroup In colGroups
If objGroup.Name = 'Administrators"
Then
For Each objUser in objGroup.Members
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_Group Where Name = '" & objUser & "'")
For Each objitem in Colitems
Wscript.Echo "SID: " & objItem.SID
Next
Next
end if
Next
These groups can contain local and domain accounts as well as local and foreign (trusted) domain groups (any combination).
I mashed some scripts together (below). Basically it checks for the "Administrators" group then parses through the list giving me the SID of the group members that are also groups.
My problem is this: the objUser variable returns the group name with no domain or server info. So when my WMI call goes out it finds anything by that particular name on any server or domain and returns the SID info for all of them.
Example: If a member is "domain1\domain admins" my script tells WMI to return the SID of anyone it finds named "Domain admins." The result in my case is 16 different SID's from 16 different domains.
Two questions:
1. How do I include domain information? I thought of the objWMIService.get but wasn't sure if that would be better or worse.
2. Is there a much better way to get the desired results?
Thanks!
-----------------
strComputer = InputBox("Server Name
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colGroups = GetObject("WinNT://" & strComputer & "")
colGroups.Filter = Array("group")
For Each objGroup In colGroups
If objGroup.Name = 'Administrators"
Then
For Each objUser in objGroup.Members
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_Group Where Name = '" & objUser & "'")
For Each objitem in Colitems
Wscript.Echo "SID: " & objItem.SID
Next
Next
end if
Next