I have a script that does a nice check to see if two groups belong to admins group on each server.
It kind of works apart from , if there is a server is the list that in no longer in AD , it returns the results from the last server.
The code below will run ok , if a server is no longer in the domain the line that reads
...psbase.children.find(”Administrators”) will sometimes error with
Exception calling "Find" with "1" argument(s): "The network path was not found.
If I can some how test for this it would be ok but i tried to trap for string and for $null but i couldnt get it to work
so $result then writes its last entry again.
$Result = @() $TestResult = @() foreach($server in (gc c:\Input\ListOfComputers.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://d30.intra/' + $server + '/'), '' -replace ('WinNT://d30.intra/', 'd30.intra\') -replace ('WinNT://', '') $members } $TestResult = ( getAdmins ) # Write-Host $TestResult.GetType().FullName $Result += Write-Output "SERVER: $server" $Result += Write-Output ' ' $Result += ( getAdmins ) if (-not ($TestResult -like '*/svc_Maneng')) { $Result += ' svc_Maneng Missing' } if (-not ($TestResult -like '*/m_DECO_COG_DPEMEA_admins')) { $Result += ' m_DECO_COG_DPEMEA_admins is Missing' } $Result += Write-Output '____________________________' $Result += Write-Output ' ' } $Result > c:\Output\output2.txt Invoke-Item c:\Output\output2.txt