search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Getting Local Administrators in all Active Directory Computers
Posted in Windows Powershell, Windows Server | 1 Comment | 3,663 views | 09/10/2009 12:55

I got an email about how to get local administrators in all computer members of Active Directory. So I created an Powershell script to do this in an easy way.

First of all, let’s find all computers in Active Directory:

1
2
3
$Searcher = New-Object DirectoryServices.DirectorySearcher([ADSI]"")
$Searcher.Filter = "(objectClass=computer)"
$Computers = ($Searcher.Findall())

Then let’s get their Local Administrators:

1
2
3
4
5
6
7
8
9
10
Foreach ($Computer in $Computers)
{
$Path=$Computer.Path
$Name=([ADSI]"$Path").Name
write-host $Name
$members =[ADSI]"WinNT://$Name/Administrators"
$members = @($members.psbase.Invoke("Members"))
$members | foreach {$_.GetType().InvokeMember("Name", 'GetProperty',
$null, $_, $null)}
}

You see How easy to get Local Administrators with Powershell? If you use Powershell V2, it is even easier.


Comments (1)

bryce rooney

June 7th, 2012
17:07:31

just starting to understand powershell how would you export the data to csv after finding local domain admins



Leave a Reply