Created
June 29, 2015 17:48
-
-
Save mortenya/fc4598fa5b581a338847 to your computer and use it in GitHub Desktop.
This script will query the computers in (Get-ADComputer -Filter *) and then output the members of BUILTIN\Administrators to c:\psresults\ListOfLocalAdministratorsGroup.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#The Third section will query each computer in the ListOfComputers.txt to get the members of the local group Administrators | |
#$Servers = (Get-ADComputer -Filter *).name | |
$output = 'c:\psresults\ListOfLocalAdministratorsGroup.txt' | |
$results = New-Object System.Collections.ArrayList | |
$objSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-544") | |
$objgroup = $objSID.Translate([System.Security.Principal.NTAccount]) | |
$objgroupname = ($objgroup.Value).Split("\")[1] | |
foreach($server in (Get-ADComputer -Filter *).name) | |
{ | |
$admins = New-Object System.Collections.ArrayList | |
$group =[ADSI]"WinNT://$server/$objgroupname" | |
$members = @($group.psbase.Invoke("Members")) | |
$members | foreach { | |
$obj = new-object psobject -Property @{ | |
Server = $Server | |
Admin = $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null) | |
} | |
#$obj | |
$admins.Add($obj) | |
} | |
$results.Add($admins) | |
} | |
$results | Out-File $Output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment