Skip to content

Commit

Permalink
Common Parameter names are reserved (#11231)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdwheeler committed Jul 2, 2024
1 parent 74c8502 commit 7ea0d42
Show file tree
Hide file tree
Showing 16 changed files with 236 additions and 105 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes the parameters that can be used with any cmdlet.
Locale: en-US
ms.date: 03/25/2024
ms.date: 07/02/2024
no-loc: [Debug, Verbose, Confirm]
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
Expand All @@ -24,7 +24,9 @@ effect on all cmdlets. For example, if a cmdlet doesn't generate any verbose
output, using the **Verbose** common parameter has no effect.

The common parameters are also available on advanced functions that use the
**CmdletBinding** attribute or the **Parameter** attribute.
`CmdletBinding` attribute or the `Parameter` attribute. When you use these
attributes, PowerShell automatically adds the Common Parameters. You can't
create any parameters that use the same names as the Common Parameters.

Several common parameters override system defaults or preferences that you set
using the PowerShell preference variables. Unlike the preference variables, the
Expand All @@ -43,6 +45,7 @@ parentheses.
- **OutVariable** (ov)
- **OutBuffer** (ob)
- **PipelineVariable** (pv)
- **ProgressAction** (proga)
- **Verbose** (vb)
- **WarningAction** (wa)
- **WarningVariable** (wv)
Expand Down Expand Up @@ -468,6 +471,40 @@ At line:1 char:1
+ FullyQualifiedErrorId : VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand
```

### -ProgressAction

Determines how PowerShell responds to progress updates generated by a script,
cmdlet, or provider, such as the progress bars generated by the
[Write-Progress][06] cmdlet. The `Write-Progress` cmdlet creates progress bars
that show a command's status. The **ProgressAction** parameter was added in
PowerShell 7.4.

The **ProgressAction** parameter takes one of the [`ActionPreference`][07]
enumeration values: `SilentlyContinue`, `Stop`, `Continue`, `Inquire`,
`Ignore`, `Suspend`, or `Break`.

The valid values are as follows:

- `Break` Enters the debugger at an occurrence of the `Write-Progress` command.
- `Stop`: Doesn't display the progress bar. Instead, it displays an error
message and stops executing.
- `Inquire`: Doesn't display the progress bar. Prompts for permission to
continue. If you reply with `Y` or `A`, it displays the progress bar.
- `Continue`: (Default) Displays the progress bar and continues with execution.
- `SilentlyContinue`: Executes the command, but doesn't display the progress
bar.

```yaml
Type: ActionPreference
Aliases: proga
Accepted values: Break, Suspend, Ignore, Inquire, Continue, Stop, SilentlyContinue
Required: False
Position: Named
Default value: Depends on preference variable
Accept pipeline input: False
Accept wildcard characters: False
```
### -Verbose
Displays detailed information about the operation done by the command. This
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: 06/22/2023
ms.date: 07/02/2024
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 All @@ -19,10 +19,9 @@ You can add parameters to the advanced functions that you write, and use
parameter attributes and arguments to limit the parameter values that function
users submit with the parameter.

The parameters that you add to your function are available to users in addition
to the common parameters that PowerShell adds automatically to all cmdlets and
advanced functions. For more information about the PowerShell common
parameters, see [about_CommonParameters][06].
When you use the `CmdletBinding` attribute, PowerShell automatically adds the
Common Parameters. You can't create any parameters that use the same names as
the Common Parameters. For more information, see [about_CommonParameters][06].

Beginning in PowerShell 3.0, you can use splatting with `@Args` to represent
the parameters in a command. Splatting is valid on simple and advanced
Expand Down Expand Up @@ -82,7 +81,7 @@ function Get-Date_Func {
}
}
[cultureinfo]::CurrentCulture = 'de-DE'
[CultureInfo]::CurrentCulture = 'de-DE'
# This German-format date string doesn't work with the invariant culture.
# E.g., [datetime] '19-06-2018' breaks.
Expand Down Expand Up @@ -205,7 +204,7 @@ they can be difficult for users to discover. To find a dynamic parameter, the
user must be in the provider path, use the **ArgumentList** parameter of the
`Get-Command` cmdlet, or use the **Path** parameter of `Get-Help`.

To create a dynamic parameter for a function or script, use the `DynamicParam`
To create a dynamic parameter for a function or script, use the `dynamicparam`
keyword.

The syntax is as follows:
Expand All @@ -227,7 +226,7 @@ function Get-Sample {
[CmdletBinding()]
param([string]$Name, [string]$Path)
DynamicParam
dynamicparam
{
if ($Path.StartsWith("HKLM:"))
{
Expand All @@ -251,7 +250,8 @@ function Get-Sample {
}
```

For more information, see the documentation for the [RuntimeDefinedParameter][02] type.
For more information, see the documentation for the
[RuntimeDefinedParameter][02] type.

## Attributes of parameters

Expand Down Expand Up @@ -730,7 +730,7 @@ more information, see [about_Wildcards][19].

The **ArgumentCompleter** attribute allows you to add tab completion values to
a specific parameter. An **ArgumentCompleter** attribute must be defined for
each parameter that needs tab completion. Like **DynamicParameters**, the
each parameter that needs tab completion. Like **dynamicparameters**, the
available values are calculated at runtime when the user presses <kbd>Tab</kbd>
after the parameter name.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes the attribute that makes a function work like a compiled cmdlet.
Locale: en-US
ms.date: 09/23/2021
ms.date: 07/02/2024
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_functions_cmdletbindingattribute?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about Functions CmdletBindingAttribute
Expand All @@ -17,6 +17,10 @@ The `CmdletBinding` attribute is an attribute of functions that makes them
operate like compiled cmdlets written in C#. It provides access to the features
of cmdlets.

When you use the `CmdletBinding` attribute, PowerShell automatically adds the
Common Parameters. You can't create any parameters that use the same names as
the Common Parameters. For more information, see [about_CommonParameters][02].

PowerShell binds the parameters of functions that have the `CmdletBinding`
attribute in the same way that it binds the parameters of compiled cmdlets. The
`$PSCmdlet` automatic variable is available to functions with the
Expand Down Expand Up @@ -90,7 +94,7 @@ be confirmed by a call to the **ShouldProcess** method. The call to the
argument is also specified.

For more information about confirmation requests, see
[Requesting Confirmation](/powershell/scripting/developer/cmdlet/requesting-confirmation).
[Requesting Confirmation][01].

## DefaultParameterSetName

Expand Down Expand Up @@ -197,7 +201,7 @@ The **Position** argument of the **Parameter** attribute takes precedence over
the **PositionalBinding** default value. You can use the **Position** argument
to specify a position value for a parameter. For more information about the
**Position** argument, see
[about_Functions_Advanced_Parameters](about_Functions_Advanced_Parameters.md).
[about_Functions_Advanced_Parameters][04].

## Notes

Expand All @@ -209,8 +213,17 @@ about_Functions_CmdletBinding_Attribute

## See also

- [about_Functions](about_Functions.md)
- [about_Functions_Advanced](about_Functions_Advanced.md)
- [about_Functions_Advanced_Methods](about_Functions_Advanced_Methods.md)
- [about_Functions_Advanced_Parameters](about_Functions_Advanced_Parameters.md)
- [about_Functions_OutputTypeAttribute](about_Functions_OutputTypeAttribute.md)
- [about_Functions][07]
- [about_Functions_Advanced][05]
- [about_Functions_Advanced_Methods][03]
- [about_Functions_Advanced_Parameters][04]
- [about_Functions_OutputTypeAttribute][06]

<!-- link references -->
[01]: /powershell/scripting/developer/cmdlet/requesting-confirmation
[02]: about_CommonParameters.md
[03]: about_Functions_Advanced_Methods.md
[04]: about_Functions_Advanced_Parameters.md
[05]: about_Functions_Advanced.md
[06]: about_Functions_OutputTypeAttribute.md
[07]: about_Functions.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Lists the reserved words that cannot be used as identifiers because they have a special meaning in PowerShell.
Locale: en-US
ms.date: 07/23/2020
ms.date: 07/02/2024
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_reserved_words?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about Reserved Words
Expand Down Expand Up @@ -44,15 +44,15 @@ enum private
(*) These keywords are reserved for future use.
```

Several language keywords, including `Foreach`, `If`, `For`, and `While`, have
Several language keywords, including `foreach`, `if`, `for`, and `while`, have
their own help articles. To view them, type `Get-Help about_` and add the
keyword. For example, to get information about the `Foreach` statement, type:
keyword. For example, to get information about the `foreach` statement, type:

```powershell
Get-Help about_ForEach
```

For information about the `Filter` statement or the `Return` statement syntax,
For information about the `filter` statement or the `return` statement syntax,
type:

```powershell
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes the parameters that can be used with any cmdlet.
Locale: en-US
ms.date: 04/02/2024
ms.date: 07/02/2024
no-loc: [Debug, Verbose, Confirm]
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters?view=powershell-7.2&WT.mc_id=ps-gethelp
schema: 2.0.0
Expand All @@ -24,7 +24,9 @@ effect on all cmdlets. For example, if a cmdlet doesn't generate any verbose
output, using the **Verbose** common parameter has no effect.

The common parameters are also available on advanced functions that use the
**CmdletBinding** attribute or the **Parameter** attribute.
`CmdletBinding` attribute or the `Parameter` attribute. When you use these
attributes, PowerShell automatically adds the Common Parameters. You can't
create any parameters that use the same names as the Common Parameters.

Several common parameters override system defaults or preferences that you set
using the PowerShell preference variables. Unlike the preference variables, the
Expand All @@ -43,6 +45,7 @@ parentheses.
- **OutVariable** (ov)
- **OutBuffer** (ob)
- **PipelineVariable** (pv)
- **ProgressAction** (proga)
- **Verbose** (vb)
- **WarningAction** (wa)
- **WarningVariable** (wv)
Expand Down Expand Up @@ -454,6 +457,40 @@ Step1[PROCESS]:$temp=4 - $_=5
Get-Variable: Cannot find a variable with the name 'temp'.
```

### -ProgressAction

Determines how PowerShell responds to progress updates generated by a script,
cmdlet, or provider, such as the progress bars generated by the
[Write-Progress][06] cmdlet. The `Write-Progress` cmdlet creates progress bars
that show a command's status. The **ProgressAction** parameter was added in
PowerShell 7.4.

The **ProgressAction** parameter takes one of the [`ActionPreference`][07]
enumeration values: `SilentlyContinue`, `Stop`, `Continue`, `Inquire`,
`Ignore`, `Suspend`, or `Break`.

The valid values are as follows:

- `Break` Enters the debugger at an occurrence of the `Write-Progress` command.
- `Stop`: Doesn't display the progress bar. Instead, it displays an error
message and stops executing.
- `Inquire`: Doesn't display the progress bar. Prompts for permission to
continue. If you reply with `Y` or `A`, it displays the progress bar.
- `Continue`: (Default) Displays the progress bar and continues with execution.
- `SilentlyContinue`: Executes the command, but doesn't display the progress
bar.

```yaml
Type: ActionPreference
Aliases: proga
Accepted values: Break, Suspend, Ignore, Inquire, Continue, Stop, SilentlyContinue
Required: False
Position: Named
Default value: Depends on preference variable
Accept pipeline input: False
Accept wildcard characters: False
```
### -Verbose
Displays detailed information about the operation done by the command. This
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: 06/22/2023
ms.date: 07/02/2024
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-7.2&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about Functions Advanced Parameters
Expand All @@ -19,10 +19,9 @@ You can add parameters to the advanced functions that you write, and use
parameter attributes and arguments to limit the parameter values that function
users submit with the parameter.

The parameters that you add to your function are available to users in addition
to the common parameters that PowerShell adds automatically to all cmdlets and
advanced functions. For more information about the PowerShell common
parameters, see [about_CommonParameters][06].
When you use the `CmdletBinding` attribute, PowerShell automatically adds the
Common Parameters. You can't create any parameters that use the same names as
the Common Parameters. For more information, see [about_CommonParameters][06].

Beginning in PowerShell 3.0, you can use splatting with `@Args` to represent
the parameters in a command. Splatting is valid on simple and advanced
Expand Down Expand Up @@ -82,7 +81,7 @@ function Get-Date_Func {
}
}
[cultureinfo]::CurrentCulture = 'de-DE'
[CultureInfo]::CurrentCulture = 'de-DE'
# This German-format date string doesn't work with the invariant culture.
# E.g., [datetime] '19-06-2018' breaks.
Expand Down Expand Up @@ -200,7 +199,7 @@ they can be difficult for users to discover. To find a dynamic parameter, the
user must be in the provider path, use the **ArgumentList** parameter of the
`Get-Command` cmdlet, or use the **Path** parameter of `Get-Help`.

To create a dynamic parameter for a function or script, use the `DynamicParam`
To create a dynamic parameter for a function or script, use the `dynamicparam`
keyword.

The syntax is as follows:
Expand All @@ -222,7 +221,7 @@ function Get-Sample {
[CmdletBinding()]
param([string]$Name, [string]$Path)
DynamicParam
dynamicparam
{
if ($Path.StartsWith("HKLM:"))
{
Expand All @@ -246,7 +245,8 @@ function Get-Sample {
}
```

For more information, see the documentation for the [RuntimeDefinedParameter][02] type.
For more information, see the documentation for the
[RuntimeDefinedParameter][02] type.

## Attributes of parameters

Expand Down Expand Up @@ -739,7 +739,7 @@ For more information, see [about_Functions_Argument_Completion][11].

The **ArgumentCompleter** attribute allows you to add tab completion values to
a specific parameter. An **ArgumentCompleter** attribute must be defined for
each parameter that needs tab completion. Like **DynamicParameters**, the
each parameter that needs tab completion. Like **dynamicparameters**, the
available values are calculated at runtime when the user presses <kbd>Tab</kbd>
after the parameter name.

Expand Down Expand Up @@ -917,10 +917,10 @@ PowerShell generates an error if any value is outside that range.

The **ValidateRangeKind** enum allows for the following values:

- **Positive** - A number greater than zero.
- **Negative** - A number less than zero.
- **NonPositive** - A number less than or equal to zero.
- **NonNegative** - A number greater than or equal to zero.
- `Positive` - A number greater than zero.
- `Negative` - A number less than zero.
- `NonPositive` - A number less than or equal to zero.
- `NonNegative` - A number greater than or equal to zero.

In the following example, the value of the **Attempts** parameter must be
between zero and ten.
Expand Down Expand Up @@ -1250,7 +1250,7 @@ intended for external usage.
- [about_Functions_OutputTypeAttribute][13]

<!-- link references -->
[01]: ./about_comment_based_help.md
[01]: about_comment_based_help.md
[02]: /dotnet/api/system.management.automation.runtimedefinedparameter
[03]: /dotnet/standard/base-types/composite-formatting#composite-format-string
[04]: /dotnet/standard/base-types/composite-formatting#format-string-component
Expand Down
Loading

0 comments on commit 7ea0d42

Please sign in to comment.