Skip to content

Fix individual commands that do not respect an explicit $false value passed to a switch parameter #25242

@surfingoldelephant

Description

@surfingoldelephant

Prerequisites

Steps to reproduce

# The *presence* of the switch selects UseWindowsPowerShellParameterSet.
# Irrespective of the switch *value*, CreateRunspacesForUseWindowsPowerShellParameterSet() is called.
# This subverts reasonable user expectation. UseWindowsPowerShell was NOT requested, yet the command
# ignores that request.
New-PSSession -UseWindowsPowerShell:$false

# Likewise, this results in [datetime] output, despite it not being requested.
$params = @{ Since = $false }
Get-Uptime @params

Context:

This is a continuation of the following issues:

Summary:

  • The first issue discusses how Get-Uptime -Since:$false is not respected. That is, despite the explicit $false value, Get-Uptime behaves as if -Since or -Since:$true was specified.
    • This behavior was deemed erroneous and the issue was labelled Up-for-grabs.
  • The second issue is a proposal by @mklement0 for a systematic change that would implicitly fix the Get-Uptime issue and other commands that exhibit the same problem.
    • This proposal was rejected due to backwards compatibility concerns.
  • I encountered at least 10 commands shipped with PowerShell that exhibit the same problem when looking into the issue further. See here.
  • Per @iSazonov in #25015:

Up-for-Grabs - we should fix all cmdlets in the repo if they implement a switch in wrong way.

List of commands to fix:

Request

Fix each command listed above individually, so that explicitly passing a $false value to the specified switch parameter is respected.

Expected behavior

-Switch:$false results in the same behavior as not passing -Switch.

Actual behavior

For the commands listed above, -Switch:$false results in the same behavior as -Switch or -Switch:$true.

Environment data

Name                           Value
----                           -----
PSVersion                      7.6.0-preview.3
PSEdition                      Core
GitCommitId                    7.6.0-preview.3
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0, 5.0, 5.1…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendation

    Type

    No type

    Projects

    Status

    Reviewed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions