Uncategorized

PowerShell is King – Test-NetConnection is annoying, gives me warnings, I don’t want that

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

image`

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

image

/mike

Categories: Uncategorized

1 reply »

  1. You’re a life saver i was looking for a fix for this and your solution was the one thing that did exactly what i wanted it to. Thanks.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.