Get Local admins with domain

This topic contains 1 reply, has 2 voices, and was last updated by  Matt Howard 1 year, 7 months ago.

  • Author
  • #58172


    Hi fellow Poshers,

    I have been looking all over the InterTubes for a way to adjust this code to return the domain for the members within the local admins group.

    $group =[ADSI]"WinNT://$computer/Administrators" 
    $members = @($group.psbase.Invoke('Members'))
    $LocalAdmins = $members | ForEach-Object {$_.GetType().InvokeMember('Name', 'GetProperty', $null, $_, $null) } 

    Running the above code will give me a list like below:

    And what I am looking for is:

    Due to restrictions I don't have access to wsman on windows 2008 server and cannot invoke-command, otherwise I would use the method mentioned in article ""

    Additionally if any of you deep web ninjas are feeling particularly randy, I'd love to understand what is going on in this command "$_.GetType().InvokeMember('Name', 'GetProperty', $null, $_, $null) "

  • #58187

    Matt Howard

    Take a look at this blog post from Jeff Hicks. He uses the ADSI method to get the local admin group members and display their domain name:

You must be logged in to reply to this topic.