locked
Export all users which has admin access from list of servers RRS feed

  • Question

  • Hi Jrv,

    I am using following script to export admin users from listed servers, but somehow the script is not listing the all users which has administration group assigned.  

    Can you please advise? 

    $servers= get-content 'C:\server.txt'
    $output = 'C:\admin_user_list.csv' 
    $results = @()
    
    foreach($server in $servers)
    {
    $admins = @()
    $group =[ADSI]"WinNT://$server/Administrators" 
    $members = @($group.psbase.Invoke("Members"))
    $members | foreach {
     $obj = new-object psobject -Property @{
     Server = $Server
     Admin = $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)
     }
     $admins += $obj
     } 
    $results += $admins
    }
    $results| Export-csv $Output -NoTypeInformation


    • Edited by Rai01 Tuesday, July 3, 2018 3:55 AM
    • Moved by Bill_Stewart Monday, July 29, 2019 7:21 PM Abandoned
    Tuesday, July 3, 2018 3:55 AM

All replies

  • Get-Content C:\server.txt |
        ForEach-Object{
            $server = $_
            $group =[ADSI]"WinNT://$server/Administrators" 
            $group.psbase.Invoke('Members') |
                ForEach-Object{
                     [pscustomobject]@{
                         Server = $server
                         Admin = $_.GetType().InvokeMember('Name', 'GetProperty', $null, $_, $null)
                     }
                } 
        }
    


    \_(ツ)_/

    • Proposed as answer by jrv Wednesday, July 4, 2018 11:25 PM
    • Unproposed as answer by jrv Thursday, July 5, 2018 1:19 AM
    • Proposed as answer by jrv Thursday, July 5, 2018 1:20 AM
    Tuesday, July 3, 2018 4:25 AM
  • The script only listing few admin users. It suppose to list all users from assigned Administrator Groups as well. 
    Tuesday, July 3, 2018 11:08 PM
  • Remotely you cannot display the members of groups and must get the group account a enumerate its members.


    \_(ツ)_/


    • Edited by jrv Tuesday, July 3, 2018 11:25 PM
    Tuesday, July 3, 2018 11:23 PM
  • Hi Jrv,

    Actually, I am trying to extract all admin users from Resultant Set of Policy --> Restricted Groups --> Administrators Group.

    I really tried hard using  Get-ADGroup -IdentityAdministrators, but not able to achieve the objective since those users are linked to GPO.

    Can you please help me with powershell script to extract those admin users for any server?

    Really appreciate 

    Wednesday, July 4, 2018 11:19 PM
  • Hi Jrv,

    Are you there?

    Thursday, July 5, 2018 1:14 AM
  • I see Jrv is your spirit animal too.
    Thursday, July 5, 2018 3:40 PM
  • Thursday, July 5, 2018 3:54 PM