During a conversation someone told me that Test-NetConnection is kind of annoying when scanning for systems and some of them are not online, or missing from DNS or something like that. And that is true, it doesn’t matter if you sending the result down the pipeline, but it does show up in the warning stream.
The annoying way
In the first sample we run Test-NetConnection using the following
$Computers = "SRVDC01","SRVDC02","SRVDC03","SRVHOST301"
$result = foreach($Computer in $Computers){
Test-NetConnection -ComputerName $Computer -CommonTCPPort SMB
}
$result
And here is the output, note the warning stream that shows up
The non annoying way
In the second sample we run Test-NetConnection using the following
$Computers = "SRVDC01","SRVDC02","SRVDC03","SRVHOST301"
$result = foreach($Computer in $Computers){
Test-NetConnection -ComputerName $Computer -CommonTCPPort SMB -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
}
$result
And here is the output
/mike
Categories: Uncategorized