Respect -Repeat/-MtuSize/-Traceroute:$false in Test-Connection#26479
Merged
iSazonov merged 2 commits intoPowerShell:masterfrom Nov 21, 2025
Merged
Respect -Repeat/-MtuSize/-Traceroute:$false in Test-Connection#26479iSazonov merged 2 commits intoPowerShell:masterfrom
iSazonov merged 2 commits intoPowerShell:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug where explicitly setting switch parameters to $false (e.g., -Repeat:$false, -MtuSize:$false, -Traceroute:$false) in Test-Connection was incorrectly treated the same as setting them to $true. The root cause was that the code checked which parameter set was active rather than the actual boolean values of the switch parameters.
Key changes:
- Changed parameter set resolution from switch statement to if-else chain that checks boolean values of
Repeat,MtuSize, andTraceroute - Updated
Repeat.IsPresenttoRepeatfor consistency with the new approach - Added three test cases to verify each switch parameter respects explicit
$falsevalues
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs | Modified BeginProcessing() and ProcessRecord() to check switch parameter boolean values instead of parameter set names; updated SetCountForTcpTest() to use implicit bool conversion |
| test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 | Added three test cases verifying that -Repeat:$false, -MtuSize:$false, and -Traceroute:$false behave like default ping operations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
iSazonov
approved these changes
Nov 21, 2025
SIRMARGIN
pushed a commit
to SIRMARGIN/PowerShell
that referenced
this pull request
Dec 12, 2025
kilasuit
pushed a commit
to kilasuit/PowerShell
that referenced
this pull request
Jan 2, 2026
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
This PR fixes the issue where
-Repeat:$false,-MtuSize:$false, and-Traceroute:$falseare not respected inTest-Connection, causing them to behave the same as their$truecounterparts.Fixes #26475
Related to #25242
PR Context
When any of these switch parameters is explicitly set to
$false, the cmdlet incorrectly performs the associated operation (continuous ping, MTU detection, or traceroute) instead of performing a standard ping. This occurs because the code uses a switch statement onParameterSetNamewithout checking the actual boolean values of the parameters.This fix changes the parameter set resolution logic from a switch statement to an if-else chain that directly checks each parameter's boolean value, ensuring that explicit
$falsevalues are properly respected.Changes
TestConnectionCommand.cs: Changed switch statement to if-else chain that checksRepeat,MtuSize, andTracerouteproperty values instead of just the parameter set nameTest-Connection.Tests.ps1to verify each switch parameter respects$falseTesting
New tests added:
Test results:
-Repeat:$falseruns continuously instead of 4 pings-MtuSize:$falsereturnsPingMtuStatusinstead ofPingStatus-Traceroute:$falsereturnsTraceStatusinstead ofPingStatusPingStatuswith 4 pingsPR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header