Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions reference/5.1/CimCmdlets/New-CimSession.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ By default, the `New-CimSession` cmdlet establishes a connection with a remote W
endpoint for two reasons: to verify that the remote server is listening on the port number that is
specified using the **Port** parameter, and to verify the specified account credentials. The
verification is accomplished using a standard WS-Identity operation. You can add the
**SkipTestConnection** switch parameter if the remote WS-Management endpoint cannot use WS-Identify,
or to reduce some data transmission time.
**SkipTestConnection** `[switch]` parameter if the remote WS-Management endpoint cannot use
WS-Identify, or to reduce some data transmission time.

```yaml
Type: System.Management.Automation.SwitchParameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,18 @@ The syntax diagrams use the following symbols:
- Parameters with no values

Some parameters don't accept input, so they don't have a parameter value.
Parameters without values are _switch parameters_. Switch parameters are used
like boolean values. They default to `$false`. When you use a switch
parameter, the value is set to `$true`.
Parameters without values are _`[switch]` parameters_. `[switch]` parameters
are used like boolean values. They default to `$false`. When you use a
`[switch]` parameter, the value is set to `$true`.

For example, the **ListImported** parameter of `Get-Command` is a switch
parameter. When you use the **ListImported** parameter, the cmdlet return
For example, the **ListImported** parameter of `Get-Command` is a `[switch]`
parameter. When you use the **ListImported** parameter, the cmdlet returns
only commands that were imported from modules in the current session.

```Syntax
Get-Command [-ListImported]
```

<!-- So what are these `[ ]`? - square brackets, duh! -->
- Brackets `[ ]` around parameters indicate optional items. A parameter and
its value can be optional. For example, the **CommandType** parameter of
`Get-Command` and its value are enclosed in brackets because they're both
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ For more information about the standard PowerShell verbs, see
## Functions with parameters

You can use parameters with functions, including named parameters, positional
parameters, switch parameters, and dynamic parameters. For more information
parameters, `[switch]` parameters, and dynamic parameters. For more information
about dynamic parameters in functions, see
[about_Functions_Advanced_Parameters][09].

Expand Down Expand Up @@ -379,13 +379,12 @@ Get-Extension myTextFile
myTextFile.txt
```

### Switch parameters
### `[switch]` parameters

A switch is a parameter that doesn't require a value. Instead, you type the
function name followed by the name of the switch parameter.
function name followed by the name of the `[switch]` parameter.

To define a switch parameter, specify the type `[switch]` before the parameter
name, as shown in the following example:
The following example shows how you define a `[switch]` parameter:

```powershell
function Switch-Item {
Expand All @@ -395,8 +394,9 @@ function Switch-Item {
}
```

When you type the `On` switch parameter after the function name, the function
displays `Switch on`. Without the switch parameter, it displays `Switch off`.
When you type the `On` `[switch]` parameter after the function name, the
function displays `Switch on`. Without the `[switch]` parameter, it displays
`Switch off`.

```powershell
Switch-Item -On
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Explains how to add parameters to advanced functions.
Locale: en-US
ms.date: 03/10/2026
ms.date: 04/08/2026
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about_Functions_Advanced_Parameters
Expand Down Expand Up @@ -178,68 +178,68 @@ param(
)
```

## Switch parameters
## `[switch]` parameters

Switch parameters are parameters that take no parameter value. Instead, they
convey a Boolean true-or-false value through their presence or absence, so that
when a switch parameter is present it has a **true** value and when absent it
has a **false** value.
`[switch]` parameters are parameters that take no parameter value. Instead,
they convey a Boolean true-or-false value through their presence or absence, so
that when a `[switch]` parameter is present it has a **true** value and when
absent it has a **false** value.

For example, the **Recurse** parameter of `Get-ChildItem` is a switch
For example, the **Recurse** parameter of `Get-ChildItem` is a `[switch]`
parameter.

To create a switch parameter in a function, specify the `[switch]` type in the
parameter definition. The following example shows the definition of a switch
parameter that could be used to provide an option to output data as a byte
array:
The following example shows the definition of a `[switch]` parameter that could
be used to provide an option to output data as a byte array:

```powershell
param([switch]$AsByteArray)
```

Switch parameters are easy to use and are preferred over Boolean parameters
`[switch]` parameters are easy to use and are preferred over Boolean parameters
that have a less natural syntax for PowerShell.

To use a switch parameter, include the parameter in the command. For example:
To use a `[switch]` parameter, include the parameter in the command. For
example:

`-IncludeAll`

To use a Boolean parameter, you must provide the parameter and a Boolean value.

`-IncludeAll $true`

When creating switch parameters, choose the parameter name carefully. Be sure
that the parameter name communicates the effect of the parameter to the user.
Avoid ambiguous terms, such as **Filter** or **Maximum** that might imply a
value is required.
When creating `[switch]` parameters, choose the parameter name carefully. Be
sure that the parameter name communicates the effect of the parameter to the
user. Avoid ambiguous terms, such as **Filter** or **Maximum** that might imply
a value is required.

### Switch parameter design considerations
### `[switch]` parameter design considerations

- Don't set a default value for a switch parameter. Switch parameter always
default to false.
- Don't make switch parameters positional. 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
- Don't set a default value for a `[switch]` parameter. `[switch]` parameters
always default to false.
- Don't make `[switch]` parameters positional. 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 them 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.
- Don't make switch parameters mandatory. The only case where it's helpful to
make a switch parameter mandatory is when it's needed to differentiate a
parameter set.
- Use the switch parameter variable directly in a conditional expression. The
`SwitchParameter` type implicitly converts to Boolean. For example:
use of `[switch]` parameters.
- Don't make `[switch]` parameters mandatory. The only case where it's helpful
to make a `[switch]` parameter mandatory is when it's needed to differentiate
a parameter set.
- Use the `[switch]` parameter variable directly in a conditional expression.
The `SwitchParameter` type implicitly converts to Boolean. For example:

```powershell
if ($MySwitch) { ... }
```

- Always base the behavior controlled by the switch on the value of the switch,
not the presence of the parameter. There are several ways to test for the
presence of a switch parameters:
- Always 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:

- `$PSBoundParameters` contains the switch parameter name as a key
- `$MyInvocation.BoundParameters` contains the switch parameter name as a key
- `$PSBoundParameters` contains the `[switch]` parameter name as a key
- `$MyInvocation.BoundParameters` contains the `[switch]` parameter name as a
key
- `$PSCmdlet.ParameterSetName` when the switch defines a unique parameter set

For example, it's possible to provide an explicit value for the switch using
Expand Down Expand Up @@ -773,7 +773,7 @@ Use the **System.Obsolete** attribute to mark parameters that are no longer
supported. This can be useful when you want to remove a parameter from a
function but you don't want to break existing scripts that use the function.

For example, consider a function that has a **NoTypeInformation** switch
For example, consider a function that has a **NoTypeInformation** `[switch]`
parameter that controls whether type information is included in the output. You
want to make that behavior the default and remove the parameter from the
function. However, you don't want to break existing scripts that use the
Expand All @@ -783,7 +783,7 @@ explains the change.
```powershell
param(
[System.Obsolete("The NoTypeInformation parameter is obsolete.")]
[SwitchParameter]$NoTypeInformation
[switch]$NoTypeInformation
)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ $PSDefaultParameterValues = @{
```

The cmdlet and parameter names can contain wildcard characters. Use `$true` and
`$false` to set values for switch parameters, such as **Verbose**. This example
sets the common parameter **Verbose** to `$true` for all commands.
`$false` to set values for `[switch]` parameters, such as **Verbose**. This
example sets the common parameter **Verbose** to `$true` for all commands.

```powershell
$PSDefaultParameterValues = @{'*:Verbose'=$true}
Expand Down Expand Up @@ -162,9 +162,9 @@ You can use a scriptblock to specify different default values for a parameter
under different conditions. PowerShell evaluates the scriptblock and uses the
result as the default parameter value.

The `Format-Table:AutoSize` key sets that switch parameter to a default value
of `$true` The `if` statement contains a condition that the `$Host.Name` must
be `ConsoleHost`.
The `Format-Table:AutoSize` key sets that `[switch]` parameter to a default
value of `$true`. The `if` statement contains a condition that the `$Host.Name`
must be `ConsoleHost`.

```powershell
$PSDefaultParameterValues = @{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ For example:

#### -RunAsAdministrator

When this switch parameter is added to your `#Requires` statement, it specifies
that the PowerShell session in which you're running the script must be started
with elevated user rights. The **RunAsAdministrator** parameter is ignored on a
non-Windows operating system. The **RunAsAdministrator** parameter was
introduced in PowerShell 4.0.
When this `[switch]` parameter is added to your `#Requires` statement, it
specifies that the PowerShell session in which you're running the script must
be started with elevated user rights. The **RunAsAdministrator** parameter is
ignored on a non-Windows operating system. The **RunAsAdministrator** parameter
was introduced in PowerShell 4.0.

For example:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ command so you don't pass more than one value for each parameter.
## Splatting with hash tables

Use a hash table to splat parameter name and value pairs. You can use this
format for all parameter types, including positional and switch parameters.
format for all parameter types, including positional and `[switch]` parameters.
Positional parameters must be assigned by name.

The following examples compare two `Copy-Item` commands that copy the Test.txt
Expand All @@ -68,7 +68,7 @@ table of parameter-name and parameter-value pairs and stores it in the
variable in a command with splatting. The At symbol (`@HashArguments`) replaces
the dollar sign (`$HashArguments`) in the command.

To provide a value for the **WhatIf** switch parameter, use `$true` or
To provide a value for the **WhatIf** `[switch]` parameter, use `$true` or
`$false`.

```powershell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ A loopback connection is created when the following conditions are met:
- The computer name to connect to is 'localhost'.
- No credentials are passed in. Current logged in user (implicit credentials) is used for the
connection.
- The **EnableNetworkAccess** switch parameter is used.
- The **EnableNetworkAccess** `[switch]` parameter is used.

For more information on loopback connections, see [New-PSSession](New-PSSession.md) document.

Expand Down
2 changes: 1 addition & 1 deletion reference/5.1/Microsoft.PowerShell.Core/Get-Help.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Get-Help Format-Table -Parameter GroupBy
```

The **Examples** parameter displays the help file's **NAME** and **SYNOPSIS** sections, and all the
Examples. You can't specify an Example number because the **Examples** parameter is a switch
Examples. You can't specify an Example number because the **Examples** parameter is a `[switch]`
parameter.

The **Parameter** parameter displays only the descriptions of the specified parameters. If you
Expand Down
6 changes: 3 additions & 3 deletions reference/5.1/Microsoft.PowerShell.Core/Where-Object.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ command.
All PowerShell comparison operators are valid in the scriptblock format. For more information,
see [about_Comparison_Operators](./About/about_Comparison_Operators.md).

- **Simplified syntax**. To enable the simiplified syntax, `Where-Object` includes 31 switch
- **Simplified syntax**. To enable the simplified syntax, `Where-Object` includes 31 `[switch]`
parameters that represent the comparison operators. The simplified syntax is easier to read and
write than the scriptblock syntax. You can combine one of the switch parameters with the
write than the scriptblock syntax. You can combine one of the `[switch]` parameters with the
**Property** and **Value** parameters to create a command that filters objects based on the
values of their properties.

Expand All @@ -271,7 +271,7 @@ command.

As shown in the example, the parameter names **Property** and **Value** are optional. The
**Property** parameter is a positional parameter mapped to position `0`. The **Value** parameter
is a positional parameter mapped to position `1`. The switch parameter, used to specify the
is a positional parameter mapped to position `1`. The `[switch]` parameter, used to specify the
comparison, can be used in any position.

The simplified syntax was introduced in Windows PowerShell 3.0. For more information, see
Expand Down
8 changes: 4 additions & 4 deletions reference/5.1/Microsoft.PowerShell.Utility/Show-Command.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ all installed modules. To find the commands in a module, select the module from
drop-down list. To select a command, click the command name.

To use the command window, select a command, either by using the Name or by clicking the command
name in the **Commands** list. Each parameter set is displayed on a separate tab. Asterisks indicate
the mandatory parameters. To enter values for a parameter, type the value in the text box or select
the value from the drop-down box. To add a switch parameter, click to select the parameter check
box.
name in the **Commands** list. Each parameter set is displayed on a separate tab. Asterisks
indicate the mandatory parameters. To enter values for a parameter, type the value in the text box
or select the value from the drop-down box. To add a `[switch]` parameter, click to select the
parameter check box.

When you're ready, you can click **Copy** to copy the command that you've created to the clipboard
or click **Run** to run the command. You can also use the **PassThru** parameter to return the
Expand Down
4 changes: 2 additions & 2 deletions reference/7.4/CimCmdlets/New-CimSession.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ By default, the `New-CimSession` cmdlet establishes a connection with a remote W
endpoint for two reasons: to verify that the remote server is listening on the port number that is
specified using the **Port** parameter, and to verify the specified account credentials. The
verification is accomplished using a standard WS-Identity operation. You can add the
**SkipTestConnection** switch parameter if the remote WS-Management endpoint cannot use WS-Identify,
or to reduce some data transmission time.
**SkipTestConnection** `[switch]` parameter if the remote WS-Management endpoint cannot use
WS-Identify, or to reduce some data transmission time.

```yaml
Type: System.Management.Automation.SwitchParameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,18 @@ The syntax diagrams use the following symbols:
- Parameters with no values

Some parameters don't accept input, so they don't have a parameter value.
Parameters without values are _switch parameters_. Switch parameters are used
like boolean values. They default to `$false`. When you use a switch
parameter, the value is set to `$true`.
Parameters without values are _`[switch]` parameters_. `[switch]` parameters
are used like boolean values. They default to `$false`. When you use a
`[switch]` parameter, the value is set to `$true`.

For example, the **ListImported** parameter of `Get-Command` is a switch
parameter. When you use the **ListImported** parameter, the cmdlet return
For example, the **ListImported** parameter of `Get-Command` is a `[switch]`
parameter. When you use the **ListImported** parameter, the cmdlet returns
only commands that were imported from modules in the current session.

```Syntax
Get-Command [-ListImported]
```

<!-- So what are these `[ ]`? - square brackets, duh! -->
- Brackets `[ ]` around parameters indicate optional items. A parameter and
its value can be optional. For example, the **CommandType** parameter of
`Get-Command` and its value are enclosed in brackets because they're both
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ For more information about the standard PowerShell verbs, see
## Functions with parameters

You can use parameters with functions, including named parameters, positional
parameters, switch parameters, and dynamic parameters. For more information
parameters, `[switch]` parameters, and dynamic parameters. For more information
about dynamic parameters in functions, see
[about_Functions_Advanced_Parameters][09].

Expand Down Expand Up @@ -403,13 +403,12 @@ Get-Extension myTextFile
myTextFile.txt
```

### Switch parameters
### `[switch]` parameters

A switch is a parameter that doesn't require a value. Instead, you type the
function name followed by the name of the switch parameter.
function name followed by the name of the `[switch]` parameter.

To define a switch parameter, specify the type `[switch]` before the parameter
name, as shown in the following example:
The following example shows how you define a `[switch]` parameter:

```powershell
function Switch-Item {
Expand All @@ -419,8 +418,9 @@ function Switch-Item {
}
```

When you type the `On` switch parameter after the function name, the function
displays `Switch on`. Without the switch parameter, it displays `Switch off`.
When you type the `On` `[switch]` parameter after the function name, the
function displays `Switch on`. Without the `[switch]` parameter, it displays
`Switch off`.

```powershell
Switch-Item -On
Expand Down
Loading