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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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