Ich möchte alle DCs prüfen ob die Netzwerktechnisch erreichbar sind. Und zwar ohne die Liste pflegen zu müssen.
Die Art wie es gemacht wird, ist mir egal. Es soll nur dynamisch alle DCs prüfen. Und die nicht erreichbaren in eine Liste schreiben. Optional die Erreichten auch in eine Liste.
Das hier habe ich gefunden. Folgenden Code. Der funktioniert zwar. Aber er prüft die Liste 4x oder so. Also wird 4x so oft gepingt. Und in die Liste tauchen dann halt auch die Dinge 4x auf.
$Forest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$AllOutput = @()
$Forest.Domains | ForEach{
[PsObject]$OutPut = "" | Select-Object DCName
$([System.DirectoryServices.ActiveDirectory.Domain]::GetDomain($DirectoryContext).DomainControllers) | ForEach{
$DC = $Output.DCName = $_.Name
#$Output
#echo $DC
if (test-connection -Computer $DC -quiet -count 2) {echo "$DC" >> Erreichbar.txt} else {echo "$DC" >> nichtErreichbar.txt}
}
}
#$AllOutput | Format-Table -AutoSize
Danke schon mal im vorraus