Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
For example, the **ListImported** parameter of `Get-Command` is a `[switch]`
parameter. When you use the **ListImported** parameter, the cmdlet return
Comment thread
michaeltlombardi marked this conversation as resolved.
Outdated
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
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`
Comment thread
michaeltlombardi marked this conversation as resolved.
Outdated
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 simiplified syntax, `Where-Object` includes 31 `[switch]`
Comment thread
michaeltlombardi marked this conversation as resolved.
Outdated
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
For example, the **ListImported** parameter of `Get-Command` is a `[switch]`
parameter. When you use the **ListImported** parameter, the cmdlet return
Comment thread
michaeltlombardi marked this conversation as resolved.
Outdated
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
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`
Comment thread
michaeltlombardi marked this conversation as resolved.
Outdated
must be `ConsoleHost`.

```powershell
$PSDefaultParameterValues = @{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ Get-Module -ListAvailable BitsTransfer
# No output
```

In both cases, the `-SkipEditionCheck` switch parameter can be used to override
this behavior:
In both cases, the `-SkipEditionCheck` `[switch]` parameter can be used to
override this behavior:

```powershell
Get-Module -ListAvailable -SkipEditionCheck BitsTransfer
Expand Down
14 changes: 7 additions & 7 deletions reference/7.4/Microsoft.PowerShell.Core/About/about_Pwsh.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ and any parameters. File must be the last parameter in the command, because all
characters typed after the File parameter name are interpreted as the script
filepath followed by the script parameters.

Typically, the switch parameters of a script are either included or omitted.
For example, the following command uses the **All** parameter of the
Typically, the `[switch]` parameters of a script are either included or
omitted. For example, the following command uses the **All** parameter of the
`Get-Script.ps1` script file: `-File .\Get-Script.ps1 -All`

In rare cases, you might need to provide a **Boolean** value for a switch
parameter. To provide a **Boolean** value for a switch parameter in the value
of the **File** parameter, Use the parameter normally followed immediately by a
colon and the boolean value, such as the following:
`-File .\Get-Script.ps1 -All:$false`.
In rare cases, you might need to provide a **Boolean** value for a `[switch]`
parameter. To provide a **Boolean** value for a `[switch]` parameter in the
value of the **File** parameter, Use the parameter normally followed
immediately by a colon and the boolean value, such as the following: `-File
.\Get-Script.ps1 -All:$false`.

Parameters passed to the script are passed as literal strings, after
interpretation by the current shell. For example, if you are in `cmd.exe` and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,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 @@ -52,7 +52,7 @@ defining a parameter in a command.
## 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 @@ -71,7 +71,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 @@ -235,7 +235,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/7.4/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/7.4/Microsoft.PowerShell.Core/Where-Object.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,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 simiplified syntax, `Where-Object` includes 31 `[switch]`
Comment thread
michaeltlombardi marked this conversation as resolved.
Outdated
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 @@ -278,7 +278,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
Loading