$Result = @() foreach($server in (gc .\servers.txt)){ $computer = [ADSI](”WinNT://” + $server + “,computer”) $Group = $computer.psbase.children.find(”Administrators”) function getAdmins {$members = $Group.psbase.invoke(”Members”) | %{$_.GetType().InvokeMember(”Adspath”, ‘GetProperty’, $null, $_, $null)} $members} $Result += $server $Result += ( getAdmins ) $Result += " " } $Result > c:\results.txt Invoke-Item c:\results.txt
I had a little extra time today, and managed to clean up the members using the -replace parameter, replace "DOMAIN" with your domain name. The updated code looks something like this:
$Result = @() foreach($server in (gc .\servers.txt)){ $computer = [ADSI](”WinNT://” + $server + “,computer”) $Group = $computer.psbase.children.find(”Administrators”) function getAdmins {$members = ($Group.psbase.invoke(”Members”) | %{$_.GetType().InvokeMember(”Adspath”, ‘GetProperty’, $null, $_, $null)}) -replace ('WinNT://DOMAIN/' + $server + '/'), '' -replace ('WinNT://DOMAIN/', 'DOMAIN\') -replace ('WinNT://', '') $members} $Result += Write-Output "SERVER: $server" $Result += Write-Output ' ' $Result += ( getAdmins ) $Result += Write-Output '____________________________' $Result += Write-Output ' ' } $Result > c:\results.txt Invoke-Item c:\results.txtYou can simply add another -replace ('WinNT://DOMAIN/', 'DOMAIN\') for each domain in the system. I know its a little hack 'n slash but it will do for now.
2 comments:
Very Good Post, cleanup is below
$Result = @()
foreach($server in (gc .\servers.txt)){
$computer = [ADSI](”WinNT://” + $server + “,computer”)
$Group = $computer.psbase.children.find(”Administrators”)
function getAdmins
{$members = ($Group.psbase.invoke(”Members”) | %{$_.GetType().InvokeMember(”Adspath”, ‘GetProperty’, $null, $_, $null)}) -replace ('WinNT://DOMAIN/' + $server + '/'), '' -replace ('WinNT://DOMAIN/', 'DOMAIN\') -replace ('WinNT://', '')
$members}
$Result += Write-Output "SERVER: $server"
$Result += Write-Output ' '
$Result += ( getAdmins )
$Result += Write-Output '____________________________'
$Result += Write-Output ' '
}
$Result > d:\results.txt
Invoke-Item d:\results.txt
Hi,
Thanks for your post. It seems my code window added some junk into the code boxes.
I have resolved that, thanks.
Post a Comment
Note: Only a member of this blog may post a comment.