From a0f51b30c98f01fadbbfdf639f0d9d734e9b1133 Mon Sep 17 00:00:00 2001 From: Mikey Lombardi Date: Wed, 8 Apr 2026 12:49:18 -0500 Subject: [PATCH] (AB-568561) `[switch]` parameter in conceptual docs --- .../developer/cmdlet/background-jobs.md | 3 +- .../cmdlet/cmdlet-dynamic-parameters.md | 2 +- .../developer/cmdlet/cmdlet-overview.md | 4 +-- ...reating-a-cmdlet-to-access-a-data-store.md | 21 ++++++------- .../how-to-declare-cmdlet-parameters.md | 5 ++-- .../how-to-declare-dynamic-parameters.md | 2 +- .../developer/cmdlet/how-to-support-jobs.md | 4 +-- .../requesting-confirmation-from-cmdlets.md | 7 +++-- ...ongly-encouraged-development-guidelines.md | 6 ++-- .../cmdlet/types-of-cmdlet-output.md | 6 ++-- .../cmdlet/types-of-cmdlet-parameters.md | 29 +++++++++--------- ...mic-parameters-to-a-provider-help-topic.md | 4 +-- ...ow-to-add-syntax-to-a-cmdlet-help-topic.md | 2 +- .../docs-conceptual/lang-spec/chapter-02.md | 2 +- .../docs-conceptual/lang-spec/chapter-04.md | 30 +++++++++---------- .../docs-conceptual/lang-spec/chapter-06.md | 2 +- .../docs-conceptual/lang-spec/chapter-08.md | 10 +++---- reference/docs-conceptual/learn/Glossary.md | 6 ++-- .../everything-about-shouldprocess.md | 11 +++---- .../deep-dives/everything-about-switch.md | 8 ++--- .../learn/ps101/02-help-system.md | 12 ++++---- .../samples/Sorting-Objects.md | 3 +- .../whats-new/What-s-New-in-PowerShell-74.md | 2 +- .../differences-from-windows-powershell.md | 8 ++--- 24 files changed, 97 insertions(+), 92 deletions(-) diff --git a/reference/docs-conceptual/developer/cmdlet/background-jobs.md b/reference/docs-conceptual/developer/cmdlet/background-jobs.md index 52e9ca8d0a6b..258cdcefb63a 100644 --- a/reference/docs-conceptual/developer/cmdlet/background-jobs.md +++ b/reference/docs-conceptual/developer/cmdlet/background-jobs.md @@ -23,7 +23,8 @@ For more information about how background jobs are handled at the command line, To write a cmdlet that can be run as a background job, you must complete the following tasks: -- Define an `asJob` switch parameter so that the user can decide whether to run the cmdlet as a background job. +- Define an `AsJob` `[switch]` parameter so that the user can decide whether to run the cmdlet as a + background job. - Create an object that derives from the [System.Management.Automation.Job](/dotnet/api/System.Management.Automation.Job) class. This object can be a custom job object or a job object provided by Windows PowerShell, such as a [System.Management.Automation.PSEventJob](/dotnet/api/System.Management.Automation.PSEventJob) object. diff --git a/reference/docs-conceptual/developer/cmdlet/cmdlet-dynamic-parameters.md b/reference/docs-conceptual/developer/cmdlet/cmdlet-dynamic-parameters.md index cc297bf9039e..f45b3c528ce6 100644 --- a/reference/docs-conceptual/developer/cmdlet/cmdlet-dynamic-parameters.md +++ b/reference/docs-conceptual/developer/cmdlet/cmdlet-dynamic-parameters.md @@ -9,7 +9,7 @@ title: Cmdlet Dynamic Parameters Cmdlets can define parameters that are available to the user under special conditions, such as when the argument of another parameter is a specific value. These parameters are added at runtime and are referred to as dynamic parameters because they're only added when needed. For example, you can -design a cmdlet that adds several parameters only when a specific switch parameter is specified. +design a cmdlet that adds several parameters only when a specific `[switch]` parameter is specified. > [!NOTE] > Providers and PowerShell functions can also define dynamic parameters. diff --git a/reference/docs-conceptual/developer/cmdlet/cmdlet-overview.md b/reference/docs-conceptual/developer/cmdlet/cmdlet-overview.md index ed5977f4c09b..a1e3101bf6c6 100644 --- a/reference/docs-conceptual/developer/cmdlet/cmdlet-overview.md +++ b/reference/docs-conceptual/developer/cmdlet/cmdlet-overview.md @@ -49,8 +49,8 @@ about this attribute, see [Cmdlet Attribute Declaration](cmdlet-attribute-declar ### Cmdlet parameter The public properties that define the parameters that are available to the user or to the -application that is running the cmdlet. Cmdlets can have required, named, positional, and *switch* -parameters. Switch parameters allow you to define parameters that are evaluated only if the +application that is running the cmdlet. Cmdlets can have required, named, positional, and `[switch]` +parameters. `[switch]` parameters allow you to define parameters that are evaluated only if the parameters are specified in the call. For more information about the different types of parameters, see [Cmdlet Parameters](cmdlet-parameters.md). diff --git a/reference/docs-conceptual/developer/cmdlet/creating-a-cmdlet-to-access-a-data-store.md b/reference/docs-conceptual/developer/cmdlet/creating-a-cmdlet-to-access-a-data-store.md index e6992c90c7fb..7d5ff7ae360b 100644 --- a/reference/docs-conceptual/developer/cmdlet/creating-a-cmdlet-to-access-a-data-store.md +++ b/reference/docs-conceptual/developer/cmdlet/creating-a-cmdlet-to-access-a-data-store.md @@ -145,10 +145,11 @@ public ScriptBlock Script ScriptBlock script; ``` -The `SimpleMatch` parameter is a switch parameter that indicates whether the cmdlet is to explicitly -match the patterns as they are supplied. When the user specifies the parameter at the command line -(`true`), the cmdlet uses the patterns as they are supplied. If the parameter is not specified -(`false`), the cmdlet uses regular expressions. The default for this parameter is `false`. +The `SimpleMatch` parameter is a `[switch]` parameter that indicates whether the cmdlet is to +explicitly match the patterns as they are supplied. When the user specifies the parameter at the +command line (`true`), the cmdlet uses the patterns as they are supplied. If the parameter is not +specified (`false`), the cmdlet uses regular expressions. The default for this parameter is +`false`. ```csharp [Parameter] @@ -160,12 +161,12 @@ public SwitchParameter SimpleMatch private bool simpleMatch; ``` -The `CaseSensitive` parameter is a switch parameter that indicates whether a case-sensitive search -is performed. When the user specifies the parameter at the command line (`true`), the cmdlet checks -for the uppercase and lowercase of characters when comparing patterns. If the parameter is not -specified (`false`), the cmdlet does not distinguish between uppercase and lowercase. For example -"MyFile" and "myfile" would both be returned as positive hits. The default for this parameter is -`false`. +The `CaseSensitive` parameter is a `[switch]` parameter that indicates whether a case-sensitive +search is performed. When the user specifies the parameter at the command line (`true`), the cmdlet +checks for the uppercase and lowercase of characters when comparing patterns. If the parameter is +not specified (`false`), the cmdlet does not distinguish between uppercase and lowercase. For +example "MyFile" and "myfile" would both be returned as positive hits. The default for this +parameter is `false`. ```csharp [Parameter] diff --git a/reference/docs-conceptual/developer/cmdlet/how-to-declare-cmdlet-parameters.md b/reference/docs-conceptual/developer/cmdlet/how-to-declare-cmdlet-parameters.md index 31dd723f9d3d..ef2d96ce67ad 100644 --- a/reference/docs-conceptual/developer/cmdlet/how-to-declare-cmdlet-parameters.md +++ b/reference/docs-conceptual/developer/cmdlet/how-to-declare-cmdlet-parameters.md @@ -5,7 +5,8 @@ title: How to Declare Cmdlet Parameters --- # How to Declare Cmdlet Parameters -These examples show how to declare named, positional, required, optional, and switch parameters. These examples also show how to define a parameter alias. +These examples show how to declare named, positional, required, optional, and `[switch]` +parameters. These examples also show how to define a parameter alias. ## How to Declare a Named Parameter @@ -69,7 +70,7 @@ For more information about the Parameter attribute, see [Parameter Attribute Dec private string userName; ``` -## How to Declare a Switch Parameter +## How to Declare a `[switch]` parameter - Define a public property as type [System.Management.Automation.SwitchParameter](/dotnet/api/System.Management.Automation.SwitchParameter), and then declare the Parameter attribute. diff --git a/reference/docs-conceptual/developer/cmdlet/how-to-declare-dynamic-parameters.md b/reference/docs-conceptual/developer/cmdlet/how-to-declare-dynamic-parameters.md index 2ed1ebee8aa9..a7814ed635fb 100644 --- a/reference/docs-conceptual/developer/cmdlet/how-to-declare-dynamic-parameters.md +++ b/reference/docs-conceptual/developer/cmdlet/how-to-declare-dynamic-parameters.md @@ -7,7 +7,7 @@ title: How to Declare Dynamic Parameters This example shows how to define dynamic parameters that are added to the cmdlet at runtime. In this example, the `Department` parameter is added to the cmdlet whenever the user specifies the -`Employee` switch parameter. For more information about dynamic parameters, see +`Employee` `[switch]` parameter. For more information about dynamic parameters, see [Cmdlet Dynamic Parameters][02]. ## To define dynamic parameters diff --git a/reference/docs-conceptual/developer/cmdlet/how-to-support-jobs.md b/reference/docs-conceptual/developer/cmdlet/how-to-support-jobs.md index 2e820f781a5e..5e03eada2f48 100644 --- a/reference/docs-conceptual/developer/cmdlet/how-to-support-jobs.md +++ b/reference/docs-conceptual/developer/cmdlet/how-to-support-jobs.md @@ -11,8 +11,8 @@ information about background jobs, see [Background Jobs](./background-jobs.md). ## To support jobs -1. Define an `AsJob` switch parameter so that the user can decide whether to run the cmdlet as a - job. +1. Define an `AsJob` `[switch]` parameter so that the user can decide whether to run the cmdlet as + a job. The following example shows an AsJob parameter declaration. diff --git a/reference/docs-conceptual/developer/cmdlet/requesting-confirmation-from-cmdlets.md b/reference/docs-conceptual/developer/cmdlet/requesting-confirmation-from-cmdlets.md index 7b18229ba4f9..f55b8e6448c3 100644 --- a/reference/docs-conceptual/developer/cmdlet/requesting-confirmation-from-cmdlets.md +++ b/reference/docs-conceptual/developer/cmdlet/requesting-confirmation-from-cmdlets.md @@ -48,9 +48,10 @@ additional confirmation. For these cases, supplement the to more finely control the scope of the **Yes to all** response to the confirmation prompt. If a cmdlet calls the [System.Management.Automation.Cmdlet.ShouldContinue][02] method, the cmdlet -must also provide a `Force` switch parameter. If the user specifies `Force` when the user invokes -the cmdlet, the cmdlet should still call [System.Management.Automation.Cmdlet.ShouldProcess][03], -but it should bypass the call to [System.Management.Automation.Cmdlet.ShouldContinue][02]. +must also provide a `Force` `[switch]` parameter. If the user specifies `Force` when the user +invokes the cmdlet, the cmdlet should still call +[System.Management.Automation.Cmdlet.ShouldProcess][03], but it should bypass the call to +[System.Management.Automation.Cmdlet.ShouldContinue][02]. [System.Management.Automation.Cmdlet.ShouldContinue][02] will throw an exception when it's called from a non-interactive environment where the user can't be prompted. Adding a `Force` parameter diff --git a/reference/docs-conceptual/developer/cmdlet/strongly-encouraged-development-guidelines.md b/reference/docs-conceptual/developer/cmdlet/strongly-encouraged-development-guidelines.md index ac6eec52d1f6..c78cef466fba 100644 --- a/reference/docs-conceptual/developer/cmdlet/strongly-encouraged-development-guidelines.md +++ b/reference/docs-conceptual/developer/cmdlet/strongly-encouraged-development-guidelines.md @@ -110,9 +110,9 @@ cmdlet, do not make the `Process` parameter for another cmdlet a If your parameter takes only `true` and `false`, define the parameter as type [System.Management.Automation.SwitchParameter](/dotnet/api/System.Management.Automation.SwitchParameter). -A switch parameter is treated as `true` when it is specified in a command. If the parameter is not -included in a command, Windows PowerShell considers the value of the parameter to be `false`. Do not -define Boolean parameters. +A `[switch]` parameter is treated as `true` when it is specified in a command. If the parameter is +not included in a command, Windows PowerShell considers the value of the parameter to be `false`. +Do not define Boolean parameters. If your parameter needs to differentiate between 3 values: $true, $false and "unspecified", then define a parameter of type Nullable\. The need for a 3rd, "unspecified" value typically occurs diff --git a/reference/docs-conceptual/developer/cmdlet/types-of-cmdlet-output.md b/reference/docs-conceptual/developer/cmdlet/types-of-cmdlet-output.md index 9010d06c97c9..8e25be27d694 100644 --- a/reference/docs-conceptual/developer/cmdlet/types-of-cmdlet-output.md +++ b/reference/docs-conceptual/developer/cmdlet/types-of-cmdlet-output.md @@ -23,9 +23,9 @@ method. We recommend that you call this method instead of the [System.Management.Automation.Host.PSHostUserInterface.WriteLine](/dotnet/api/System.Management.Automation.Host.PSHostUserInterface.WriteLine) methods. -You can provide a **PassThru** switch parameter for cmdlets that do not typically return objects. -When the **PassThru** switch parameter is specified at the command line, the cmdlet is asked to -return an object. For an example of a cmdlet that has a **PassThru** parameter, see +You can provide a **PassThru** `[switch]` parameter for cmdlets that do not typically return +objects. When the **PassThru** `[switch]` parameter is specified at the command line, the cmdlet is +asked to return an object. For an example of a cmdlet that has a **PassThru** parameter, see [Add-History](/powershell/module/Microsoft.PowerShell.Core/Add-History). ### Error output diff --git a/reference/docs-conceptual/developer/cmdlet/types-of-cmdlet-parameters.md b/reference/docs-conceptual/developer/cmdlet/types-of-cmdlet-parameters.md index 18076e75d47a..3cb861241092 100644 --- a/reference/docs-conceptual/developer/cmdlet/types-of-cmdlet-parameters.md +++ b/reference/docs-conceptual/developer/cmdlet/types-of-cmdlet-parameters.md @@ -6,7 +6,7 @@ title: Types of Cmdlet Parameters # Types of Cmdlet Parameters This topic describes the different types of parameters that you can declare in cmdlets. Cmdlet -parameters can be positional, named, required, optional, or switch parameters. +parameters can be positional, named, required, optional, or `[switch]` parameters. ## Positional and Named Parameters @@ -98,18 +98,17 @@ public string UserName private string userName; ``` -## Switch Parameters +## `[switch]` parameters PowerShell provides a [System.Management.Automation.SwitchParameter][02] type that allows you to define a parameter whose default value `false` unless the parameter is specified when the cmdlet is -called. Whenever possible, use switch parameters instead of Boolean parameters. +called. Whenever possible, use `[switch]` parameters instead of Boolean parameters. Consider the following example. Many PowerShell cmdlets return output. However, these cmdlets have a -`PassThru` switch parameter that overrides the default behavior. When you use the `PassThru` +`PassThru` `[switch]` parameter that overrides the default behavior. When you use the `PassThru` parameter, the cmdlet returns output objects to the pipeline. -To define a switch parameter, declare the property as the `[SwitchParameter]` type, as shown in the -following sample. +The following sample shows how to define a `[switch]` parameter: ```csharp [Parameter()] @@ -135,18 +134,18 @@ protected override void ProcessRecord() } // End ProcessRecord ``` -By default, switch parameters are excluded from positional parameters. You _can_ override that in -the **Parameter** attribute, but it can confuse users. +By default, `[switch]` parameters are excluded from positional parameters. You _can_ override that +in the **Parameter** attribute, but it can confuse users. -Design switch parameters so that using parameter changes the default behavior of the command to a -less common or more complicated mode. The simplest behavior of a command should be the default -behavior that doesn't require the use of switch parameters. Base the behavior controlled by the -switch on the value of the switch, not the presence of the parameter. +Design `[switch]` parameters so that using the parameter changes the default behavior of the +command to a less common or more complicated mode. The simplest behavior of a command should be the +default behavior that doesn't require the use of `[switch]` parameters. Base the behavior +controlled by the `[switch]` parameter on the _value_ of the parameter, not its _presence_. -There are several ways to test for the presence of a switch parameters: +There are several ways to test for the presence of a `[switch]` parameter: -- `Invocation.BoundParameters` contains the switch parameter name as a key -- `PSCmdlet.ParameterSetName` when the switch defines a unique parameter set +- `MyInvocation.BoundParameters` contains the `[switch]` parameter name as a key +- `PSCmdlet.ParameterSetName` when the `[switch]` parameter defines a unique parameter set For example, it's possible to provide an explicit value for the switch using `-MySwitch:$false` or splatting. If you only test for the presence of the parameter, the command behaves as if the switch diff --git a/reference/docs-conceptual/developer/help/how-to-add-dynamic-parameters-to-a-provider-help-topic.md b/reference/docs-conceptual/developer/help/how-to-add-dynamic-parameters-to-a-provider-help-topic.md index 1b9d05dbda24..9b60c98dc7d3 100644 --- a/reference/docs-conceptual/developer/help/how-to-add-dynamic-parameters-to-a-provider-help-topic.md +++ b/reference/docs-conceptual/developer/help/how-to-add-dynamic-parameters-to-a-provider-help-topic.md @@ -115,8 +115,8 @@ If a provider doesn't implement any dynamic parameters, the provider help topic 1. Add the `PossibleValues` element and its child elements. Together, these elements describe the values of the dynamic parameter. This element is designed for enumerated values. If the dynamic - parameter doesn't take a value, such as is the case with a switch parameter, or the values can't - be enumerated, add an empty `PossibleValues` element. + parameter doesn't take a value, such as is the case with a `[switch]` parameter, or the values + can't be enumerated, add an empty `PossibleValues` element. The following table lists and describes the `PossibleValues` element and its child elements. diff --git a/reference/docs-conceptual/developer/help/how-to-add-syntax-to-a-cmdlet-help-topic.md b/reference/docs-conceptual/developer/help/how-to-add-syntax-to-a-cmdlet-help-topic.md index 9d74515d543f..e85f13a083ea 100644 --- a/reference/docs-conceptual/developer/help/how-to-add-syntax-to-a-cmdlet-help-topic.md +++ b/reference/docs-conceptual/developer/help/how-to-add-syntax-to-a-cmdlet-help-topic.md @@ -109,7 +109,7 @@ aren't required, because they're one of several values that might be used with t List all values of enumerations, such as the `-Type` parameter in the previous example, which can be set to **basic** or **advanced**. - Switch parameters, such as `-List` in the previous example, don't have values. + `[switch]` parameters, such as `-List` in the previous example, don't have values. 1. Add angle brackets to parameters values that are placeholder, as compared to parameter values that are literals. diff --git a/reference/docs-conceptual/lang-spec/chapter-02.md b/reference/docs-conceptual/lang-spec/chapter-02.md index ae07fc8c7113..3e0f0e0057fd 100644 --- a/reference/docs-conceptual/lang-spec/chapter-02.md +++ b/reference/docs-conceptual/lang-spec/chapter-02.md @@ -556,7 +556,7 @@ matching parameters to arguments is called _parameter binding_. There are three kinds of argument: -- Switch parameter ([§8.10.5][§8.10.5]) -- This has the form _command-parameter_ where +- `[switch]` parameter ([§8.10.5][§8.10.5]) -- This has the form _command-parameter_ where _first-parameter-char_ and _parameter-chars_ together make up the switch name, which corresponds to the name of a parameter (without its leading `-`) in the command being invoked. If the trailing colon is omitted, the presence of this argument indicates that the corresponding parameter be set diff --git a/reference/docs-conceptual/lang-spec/chapter-04.md b/reference/docs-conceptual/lang-spec/chapter-04.md index b8eb70831dcb..4561e7b199e3 100644 --- a/reference/docs-conceptual/lang-spec/chapter-04.md +++ b/reference/docs-conceptual/lang-spec/chapter-04.md @@ -869,21 +869,21 @@ In PowerShell, this type is `System.Management.Automation.ExternalScriptInfo`. This type encapsulates the state of a function. It has the following accessible members: -| **Member** | **Member Kind** | **Type** | **Purpose** | -| ------------------- | ------------------------------ | ------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| CmdletBinding | Instance property (read-only) | bool | Indicates whether the function uses the same parameter binding that compiled cmdlets use (see [§12.3.5][§12.3.5]). | -| CommandType | Instance property (read-only) | Implementation defined | Can be compared for equality with "Function" or "Filter" to see which of those this object represents. | -| DefaultParameterSet | Instance property (read-only) | string | Specifies the parameter set to use if that cannot be determined from the arguments (see [§12.3.5][§12.3.5]). | -| Definition | Instance property (read-only) | string | A string version of ScriptBlock | -| Description | Instance property (read-write) | string | The description of the function. | -| Module | Instance property (read-only) | Implementation defined ([§4.5.12][§4.5.12]) | The module from which this function was exported | -| ModuleName | Instance property (read-only) | string | The module in which this function was defined | -| Name | Instance property (read-only) | string | The name of the function | -| Options | Instance property (read-write) | Implementation defined | The scope options for the function ([§3.5.4][§3.5.4]). | -| OutputType | Instance property (read-only) | Implementation defined collection | Specifies the types of the values output, in order (see [§12.3.6][§12.3.6]). | -| Parameters | Instance property (read-only) | Implementation defined collection | Specifies the parameter names, in order. If the function acts like a cmdlet (see CmdletBinding above) the [common parameters][common parameters] are included at the end of the collection. | -| ParameterSets | Instance property (read-only) | Implementation defined collection | Information about the parameter sets associated with the command. For each parameter, the result shows the parameter name and type, and indicates if the parameter is mandatory, by position or a switch parameter. If the function acts like a cmdlet (see CmdletBinding above) the [common parameters][common parameters] are included at the end of the collection. | -| ScriptBlock | Instance property (read-only) | scriptblock ([§4.3.6][§4.3.6]) | The body of the function | +| **Member** | **Member Kind** | **Type** | **Purpose** | +| ------------------- | ------------------------------ | ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| CmdletBinding | Instance property (read-only) | bool | Indicates whether the function uses the same parameter binding that compiled cmdlets use (see [§12.3.5][§12.3.5]). | +| CommandType | Instance property (read-only) | Implementation defined | Can be compared for equality with "Function" or "Filter" to see which of those this object represents. | +| DefaultParameterSet | Instance property (read-only) | string | Specifies the parameter set to use if that cannot be determined from the arguments (see [§12.3.5][§12.3.5]). | +| Definition | Instance property (read-only) | string | A string version of ScriptBlock | +| Description | Instance property (read-write) | string | The description of the function. | +| Module | Instance property (read-only) | Implementation defined ([§4.5.12][§4.5.12]) | The module from which this function was exported | +| ModuleName | Instance property (read-only) | string | The module in which this function was defined | +| Name | Instance property (read-only) | string | The name of the function | +| Options | Instance property (read-write) | Implementation defined | The scope options for the function ([§3.5.4][§3.5.4]). | +| OutputType | Instance property (read-only) | Implementation defined collection | Specifies the types of the values output, in order (see [§12.3.6][§12.3.6]). | +| Parameters | Instance property (read-only) | Implementation defined collection | Specifies the parameter names, in order. If the function acts like a cmdlet (see CmdletBinding above) the [common parameters][common parameters] are included at the end of the collection. | +| ParameterSets | Instance property (read-only) | Implementation defined collection | Information about the parameter sets associated with the command. For each parameter, the result shows the parameter name and type, and indicates if the parameter is mandatory, by position or a `[switch]` parameter. If the function acts like a cmdlet (see CmdletBinding above) the [common parameters][common parameters] are included at the end of the collection. | +| ScriptBlock | Instance property (read-only) | scriptblock ([§4.3.6][§4.3.6]) | The body of the function | In PowerShell, this type is `System.Management.Automation.FunctionInfo`. diff --git a/reference/docs-conceptual/lang-spec/chapter-06.md b/reference/docs-conceptual/lang-spec/chapter-06.md index 84be60cef3af..5a9fc9bf42bb 100644 --- a/reference/docs-conceptual/lang-spec/chapter-06.md +++ b/reference/docs-conceptual/lang-spec/chapter-06.md @@ -36,7 +36,7 @@ The rules for converting any value to type bool are as follows: converted to True. - A value of null type is converted to False. - A string of length 0 is converted to False; a string of length > 0 is converted to True. -- A switch parameter with value `$true` is converted to True, and one with value `$false` is +- A `[switch]` parameter with value `$true` is converted to True, and one with value `$false` is converted to False. - All other non-null reference type values are converted to True. diff --git a/reference/docs-conceptual/lang-spec/chapter-08.md b/reference/docs-conceptual/lang-spec/chapter-08.md index aeeb91a28f27..4adf884d3de3 100644 --- a/reference/docs-conceptual/lang-spec/chapter-08.md +++ b/reference/docs-conceptual/lang-spec/chapter-08.md @@ -228,8 +228,8 @@ governing arguments are as follows: - Putting parentheses around an argument causes that expression to be evaluated with the result being passed instead of the text of the original expression. -- To pass an argument that looks like a switch parameter ([§2.3.4][§2.3.4]) but is not intended as - such, enclose that argument in quotes. +- To pass an argument that looks like a `[switch]` parameter ([§2.3.4][§2.3.4]) but is not intended + as such, enclose that argument in quotes. - When specifying an argument that matches a parameter having the `[switch]` type constraint ([§8.10.5][§8.10.5]), the presence of the argument name on its own causes that parameter to be @@ -1386,7 +1386,7 @@ Find-Str "abcabc" 2 # 2nd argument present, so it is used for $StartPos ### 8.10.5 The [switch] type constraint -When a switch parameter is passed, the corresponding parameter in the command must be constrained by +When a `[switch]` parameter is passed, the corresponding parameter in the command must be constrained by the type switch. Type switch has two values, True and False. Consider the following function definition and calls: @@ -1637,8 +1637,8 @@ Several of these steps involve conversion, as described in [§6.][§6.] However, used in binding is not exactly the same as that used in language conversions. Specifically, - Although the value `$null` can be cast to bool, `$null` cannot be bound to `bool`. -- When the value `$null` is passed to a switch parameter for a cmdlet, it is treated as if `$true` - was passed. However, when passed to a switch parameter for a function, it is treated as if +- When the value `$null` is passed to a `[switch]` parameter for a cmdlet, it is treated as if `$true` + was passed. However, when passed to a `[switch]` parameter for a function, it is treated as if `$false` was passed. - Parameters of type bool or switch can only bind to numeric or bool arguments. - If the parameter type is not a collection, but the argument is some sort of collection, no diff --git a/reference/docs-conceptual/learn/Glossary.md b/reference/docs-conceptual/learn/Glossary.md index d071f004646d..fdcd8d756097 100644 --- a/reference/docs-conceptual/learn/Glossary.md +++ b/reference/docs-conceptual/learn/Glossary.md @@ -196,10 +196,10 @@ a module manifest. The script defines the members that the script module exports The command interpreter that's used to pass commands to the operating system. -### switch parameter +### `[switch]` parameter -A parameter that doesn't take an argument. The value of a switch parameter defaults to `$false`. -When a switch parameter is used, its value becomes `$true`. +A parameter that doesn't take an argument. The value of a `[switch]` parameter defaults to +`$false`. When a `[switch]` parameter is used, its value becomes `$true`. ## T diff --git a/reference/docs-conceptual/learn/deep-dives/everything-about-shouldprocess.md b/reference/docs-conceptual/learn/deep-dives/everything-about-shouldprocess.md index 21ae139dfa1a..848f8cf0b0c5 100644 --- a/reference/docs-conceptual/learn/deep-dives/everything-about-shouldprocess.md +++ b/reference/docs-conceptual/learn/deep-dives/everything-about-shouldprocess.md @@ -84,13 +84,14 @@ S - Pause the current pipeline and return to the command prompt. Type "exit" to This prompt is localized in PowerShell so the language changes based on the language of your operating system. This is one more thing that PowerShell manages for you. -### Switch parameters +### `[switch]` parameters -Let's take quick moment to look at ways to pass a value to a switch parameter. The main reason I -call this out is that you often want to pass parameter values to functions you call. +Let's take a quick moment to look at ways to pass a value to a `[switch]` parameter. The main +reason I call this out is that you often want to pass parameter values to functions you call. -The first approach is a specific parameter syntax that can be used for all parameters but you mostly -see it used for switch parameters. You specify a colon to attach a value to the parameter. +The first approach is a specific parameter syntax that can be used for all parameters but you +mostly see it used for `[switch]` parameters. You specify a colon to attach a value to the +parameter. ```powershell Remove-Item -Path:* -WhatIf:$true diff --git a/reference/docs-conceptual/learn/deep-dives/everything-about-switch.md b/reference/docs-conceptual/learn/deep-dives/everything-about-switch.md index 42d67acebf83..6ba75c434006 100644 --- a/reference/docs-conceptual/learn/deep-dives/everything-about-switch.md +++ b/reference/docs-conceptual/learn/deep-dives/everything-about-switch.md @@ -180,18 +180,18 @@ in the next section where this variable is used. ## Parameters -A unique feature of the PowerShell `switch` is that it has a number of switch parameters that +A unique feature of the PowerShell `switch` is that it has a number of `[switch]` parameters that change how it performs. ### -CaseSensitive The matches aren't case-sensitive by default. If you need to be case-sensitive, you can use -`-CaseSensitive`. This can be used in combination with the other switch parameters. +`-CaseSensitive`. This can be used in combination with the other `[switch]` parameters. ### -Wildcard -We can enable wildcard support with the `-Wildcard` switch. This uses the same wildcard logic as the -`-like` operator to do each match. +We can enable wildcard support with the `-Wildcard` `[switch]` parameter. This uses the same +wildcard logic as the `-like` operator to do each match. ``` powershell $Message = 'Warning, out of disk space' diff --git a/reference/docs-conceptual/learn/ps101/02-help-system.md b/reference/docs-conceptual/learn/ps101/02-help-system.md index dd85115358f9..7fbc1457f2c5 100644 --- a/reference/docs-conceptual/learn/ps101/02-help-system.md +++ b/reference/docs-conceptual/learn/ps101/02-help-system.md @@ -251,14 +251,14 @@ Furthermore, **InstanceId** has its own pair of square brackets, indicating that parameter similar to the **LogName** parameter. Following the datatype, an empty set of square brackets implies that **InstanceId** can accept multiple values. -### Switch parameters +### `[switch]` parameters -A parameter that doesn't require a value is called a switch parameter. You can easily identify -switch parameters because there's no datatype following the parameter name. When you specify a -switch parameter, its value is `true`. When you don't specify a switch parameter, its value is -`false`. +A parameter that doesn't require a value is called a `[switch]` parameter. You can easily identify +`[switch]` parameters because there's no datatype following the parameter name. When you specify a +`[switch]` parameter, its value is `true`. When you don't specify a `[switch]` parameter, its value +is `false`. -The second parameter set includes a **List** parameter, which is a switch parameter. When you +The second parameter set includes a **List** parameter, which is a `[switch]` parameter. When you specify the **List** parameter, it returns a list of event logs on the local computer. ```Syntax diff --git a/reference/docs-conceptual/samples/Sorting-Objects.md b/reference/docs-conceptual/samples/Sorting-Objects.md index 6d6b24f91599..d424924ad276 100644 --- a/reference/docs-conceptual/samples/Sorting-Objects.md +++ b/reference/docs-conceptual/samples/Sorting-Objects.md @@ -35,7 +35,8 @@ LastWriteTime Name ... ``` -You can also sort the objects in reverse order by specifying the **Descending** switch parameter. +You can also sort the objects in reverse order by specifying the **Descending** `[switch]` +parameter. ```powershell Get-ChildItem | diff --git a/reference/docs-conceptual/whats-new/What-s-New-in-PowerShell-74.md b/reference/docs-conceptual/whats-new/What-s-New-in-PowerShell-74.md index 252b3cd4a804..40b965ef387d 100644 --- a/reference/docs-conceptual/whats-new/What-s-New-in-PowerShell-74.md +++ b/reference/docs-conceptual/whats-new/What-s-New-in-PowerShell-74.md @@ -160,7 +160,7 @@ Many thanks to **@CarloToso** and others for all the work on improving web cmdle - Add `Get-SecureRandom` cmdlet ([#19587][19587]) - `Set-Clipboard -AsOSC52` for remote usage ([#18222][18222]) (Thanks @dkaszews!) - Speed up `Resolve-Path` relative path resolution ([#19171][19171]) (Thanks @MartinGC94!) -- Added the switch parameter `-CaseInsensitive` to `Select-Object` and `Get-Unique` cmdlets +- Added the `[switch]` parameter `-CaseInsensitive` to `Select-Object` and `Get-Unique` cmdlets ([#19683][19683]) (Thanks @ArmaanMcleod!) - `Restart-Computer` and `Stop-Computer` should fail with error when not running via sudo on Unix ([#19824][19824]) diff --git a/reference/docs-conceptual/whats-new/differences-from-windows-powershell.md b/reference/docs-conceptual/whats-new/differences-from-windows-powershell.md index 53e5666418f8..6355e8e42a35 100644 --- a/reference/docs-conceptual/whats-new/differences-from-windows-powershell.md +++ b/reference/docs-conceptual/whats-new/differences-from-windows-powershell.md @@ -318,8 +318,8 @@ was added. Switch values are also supported. ## Improved backwards compatibility with Windows PowerShell -For Windows, a new switch parameter **UseWindowsPowerShell** is added to `Import-Module`. This -switch creates a proxy module in PowerShell 7 that uses a local Windows PowerShell process to +For Windows, a new `[switch]` parameter **UseWindowsPowerShell** is added to `Import-Module`. This +parameter creates a proxy module in PowerShell 7 that uses a local Windows PowerShell process to implicitly run any cmdlets contained in that module. For more information, see [Import-Module][14]. For more information on which Microsoft modules work with PowerShell 7.0, see the @@ -818,8 +818,8 @@ When PowerShell starts up, it automatically includes `$windir\System32` as part `PSModulePath` environment variable. However, it only exposes modules to `Get-Module` and `Import-Module` if its `CompatiblePSEdition` is marked as compatible with `Core`. -You can override this behavior to show all modules using the `-SkipEditionCheck` switch parameter. -We've also added a `PSEdition` property to the table output. +You can override this behavior to show all modules using the `-SkipEditionCheck` `[switch]` +parameter. We've also added a `PSEdition` property to the table output. ### `-lp` alias for all `-LiteralPath` parameters