none
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

Answers

  • 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)
    		$Name
        }
    }
    
    # Specify the computer.
    $strComputer = gc env:computername
    "Computer: $strComputer"
    $computer = [adsi]"WinNT://$strComputer"
    $objCount = ($computer.psbase.children | measure-object).count
    $i=0
    foreach($adsiObj in $computer.psbase.children)
    {
      switch -regex($adsiObj.psbase.SchemaClassName)
        {
           "group" 
    	   { $group = $adsiObj.name
    	   EnumLocalGroup $group }
       } #end switch
      $i++
    } #end foreach
    

    Thursday, July 24, 2014 8:07 AM