PS Script to find the list of users and the groups in a Workgroup server RRS feed

  • Question

  • Hi There, could you please explain on how to get a complete list of local users and local groups in a "Workgroup" server to which they belong to using Powershell. I'm able to get the users list but couldn't find any help in finding the script to find to which localgroup the user belong to. Anticipating your response. Also let me know the cmdlet for Win2k3 servers to find the same.

    Thursday, July 24, 2014 7:30 AM


  • Here's some code from David Pham (don't remember wher I fund this code):

    Trap {"Error: $_"; Break;}
    Function EnumLocalGroup($LocalGroup)
    	$Group = [ADSI]"WinNT://$strComputer/$LocalGroup,group"
    	"Group: $LocalGroup"
        # Invoke the Members method and convert to an array of member objects.
        $Members= @($Group.psbase.Invoke("Members"))
        ForEach ($Member In $Members)
            $Name = $Member.GetType().InvokeMember("Name", 'GetProperty', $Null, $Member, $Null)
    # Specify the computer.
    $strComputer = gc env:computername
    "Computer: $strComputer"
    $computer = [adsi]"WinNT://$strComputer"
    $objCount = ($computer.psbase.children | measure-object).count
    foreach($adsiObj in $computer.psbase.children)
      switch -regex($adsiObj.psbase.SchemaClassName)
    	   { $group = $
    	   EnumLocalGroup $group }
       } #end switch
    } #end foreach

    Thursday, July 24, 2014 8:07 AM