ginolard
-
Total Posts
:
1347
- Scores: 23
-
Reward points
:
0
- Joined: 8/11/2005
-
Status: offline
|
Enumerating group membership on a remote machine with WMI
Monday, April 28, 2008 8:06 PM
( permalink)
I recently came across some VB.NET code that used WMI to enumerate local group membership on a remote machine using WMI. I had always used the WINNT provider because I didn't think WMI could do it. The problem with the WINNT provider for this sort of thing is that it is painfully slow. Doing it with WMI is much, much faster. So, here you go.
Option Explicit
GetLocalGroupMembership("COMPUTER1")
Sub GetLocalGroupMembership(strComputer)
Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Dim colItems : Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Group where domain='" & strComputer &"'")
Dim objItem
For Each objItem In colItems
WScript.Echo "**** " & objitem.Name & " ****"
GetUsersFromGroup strComputer,objitem.Name,objWMIService
Next
End Sub
Sub GetUsersFromGroup (comp,grp,objWMI)
Dim strQuery : strQuery = "select * from Win32_GroupUser where GroupComponent = " & _
chr(34) & "Win32_Group.Domain='" & comp & "',Name='" & grp & "'" & Chr(34)
Dim ColItems : Set ColItems = objWMI.ExecQuery(strQuery)
Dim path
Dim NamesArray
For Each path In ColItems
NamesArray = Split(path.PartComponent,",")
WScript.Echo Replace(Replace(NamesArray(1),Chr(34),""),"Name=","")
Next
End Sub
|
|
|
|
ginolard
-
Total Posts
:
1347
- Scores: 23
-
Reward points
:
0
- Joined: 8/11/2005
-
Status: offline
|
RE: Enumerating group membership on a remote machine with WMI
Wednesday, May 28, 2008 5:51 AM
( permalink)
Has anyone had problems running this against Win2K machines?
|
|
|
|
4scriptmoni
-
Total Posts
:
225
- Scores: 0
-
Reward points
:
0
- Joined: 5/3/2007
-
Status: offline
|
RE: Enumerating group membership on a remote machine with WMI
Friday, July 29, 2011 9:09 AM
( permalink)
Do u have the code for the WINNT provider?
|
|
|
|