Enumerating group membership on a remote machine with WMI

Author Message
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)
0
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
 
 
 
 
 

Author of ManagePC - http://managepc.net

 
#1
    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)
    0
    Has anyone had problems running this against Win2K machines?
    Author of ManagePC - http://managepc.net

     
    #2
      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)
      0
       
      Do u have the code for the WINNT provider?
       
       
      #3

        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • New Messages
        • No New Messages
        • Hot Topic w/ New Messages
        • Hot Topic w/o New Messages
        • Locked w/ New Messages
        • Locked w/o New Messages
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2012 ASPPlayground.NET Forum Version 3.9