Powershell
Do{$DC=(Get-ADDomainController-Filter{IsReadOnly-eq$false}|sortname-Descending|select-Skip$DCIterator-First1).nameIf(!(Get-ADUser$SamAccountName-Server$DC-ErrorAction'SilentlyContinue')){Write-Error-Message"Some error message"}Else{$DCSelected=$DC}$DCIterator++}While($DCSelected-eq$null)The above code contains two additions to what runs in production. 1) "-ErrorAction 'SilentlyContinue'"; and 2) "Write-Error -Message "Some error message""
In testing, I attempted many permutations of code trying to achieve the effect one would expect from the above. However, what I get are standard error messages of not finding the account, but never my custom...