Get Local admins with domain

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Matt Howard Matt Howard 2 weeks, 6 days ago.

  • Author
    Posts
  • #58172
    Profile photo of GonePoshing
    GonePoshing
    Participant

    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:
    admins
    admins

    And what I am looking for is:
    domain1\admins
    domain2\admins

    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 "https://powershell.org/2013/04/02/get-local-admin-group-members-in-a-new-old-way/"

    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
    Profile photo of Matt Howard
    Matt Howard
    Participant

    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: http://jdhitsolutions.com/blog/powershell/4908/get-local-group-members-with-powershell

You must be logged in to reply to this topic.