Test common web ports concurrently from PowerShell
Build a paste-ready command, then review its compatibility and effects before running it.
80,443,8080,8443 | ForEach-Object -Parallel { $port=$_; $ok=Test-NetConnection <host> -Port $port -InformationLevel Quiet; [pscustomobject]@{Port=$port;Reachable=$ok} } -ThrottleLimit 4Complete required fields to copy the generated command.
Compatibility
PowerShell 7+Uses ForEach-Object -Parallel, which is unavailable in Windows PowerShell 5.1.
Operational knowledgereview due 2027-01-19
Requirements8080 must be installed and available on PATH.Network accessThe target must be reachable from the current environment.
Version support80 Current supported releasesVerified for windows using powershell syntax; consult compatibility notes for platform-specific differences.
Expected signalsPort ReachableRepresentative successful output; values vary with the selected target and system state.
Known errors80: command not found80 is missing or is not available on PATH.
Verify80,443,8080,8443 | ForEach-Object -Parallel { $port=$_; $ok=Test-NetConnection {{host}} -Port $port -InformationLevel Quiet; [pscustomobject]@{Port=$port;Reachable=$ok} } -ThrottleLimit 4The output matches the expected target and exits without an error.Rollback noteNot required: this command is read-only and does not change system state.
Command breakdown
0180,443,8080,8443CommandRuns the 80,443,8080,8443 stage of this one-liner.
02|PipelinePasses the output on the left to the command on the right.
03ForEach-ObjectCommandRuns the ForEach-Object stage of this one-liner.
04-ParallelOptionConfigures ForEach-Object with the -Parallel option.
05{ArgumentPasses { to ForEach-Object.
06$port=$_VariableExpands a value from the current shell environment or loop.
07;Command separatorEnds this shell statement before the next one begins.
08$ok=Test-NetConnectionVariable assignmentSets a value used by the commands that follow.
09<host>CommandRuns the <host> stage of this one-liner.
10-PortOptionConfigures <host> with the -Port option.
11$portVariableExpands a value from the current shell environment or loop.
12-InformationLevelOptionConfigures <host> with the -InformationLevel option.
13QuietArgumentPasses Quiet to <host>.
14;Command separatorEnds this shell statement before the next one begins.
15[pscustomobject]@{Port=$portCommandRuns the [pscustomobject]@{Port=$port stage of this one-liner.
16;Command separatorEnds this shell statement before the next one begins.
17Reachable=$ok}Variable assignmentSets a value used by the commands that follow.
18}CommandRuns the } stage of this one-liner.
19-ThrottleLimitOptionConfigures } with the -ThrottleLimit option.
This advanced community-curated one-liner combines several stages. Review every option and placeholder before running it.
Example input
80,443,8080,8443 | ForEach-Object -Parallel { $port=$_; $ok=Test-NetConnection example.com -Port $port -InformationLevel Quiet; [pscustomobject]@{Port=$port;Reachable=$ok} } -ThrottleLimit 4
Example output
Port Reachable
---- ---------
80 True
443 True
8080 False
8443 False
Illustrative output — exact values vary by system and data.
Official sources