Skip to content

Instantly share code, notes, and snippets.

@karoltheguy
Created June 1, 2021 19:43
Show Gist options
  • Save karoltheguy/a68ccff6905aaa0ae9483783fec84e03 to your computer and use it in GitHub Desktop.
Save karoltheguy/a68ccff6905aaa0ae9483783fec84e03 to your computer and use it in GitHub Desktop.
Test connections on a list of ports from a list of remote hosts
$serverlist = "localhost", "127.0.0.1" #hosts to test FROM
$target = "google.ca"
$portlist = 8199, 8198, 8197
Write-Host "Target: $target"
foreach ($s in $serverlist) {
Write-Host "--------------------------"
Invoke-Command -ComputerName $s -ScriptBlock {
foreach ($p in $Using:portlist) {
$connection = Test-NetConnection -ComputerName $Using:target -Port $p
Write-Host $Using:s on $p : $connection.TcpTestSucceeded
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment