diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_CommonParameters.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_CommonParameters.md index 248bb57d11ea..a965dfc6624f 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_CommonParameters.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_CommonParameters.md @@ -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 @@ -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 @@ -43,6 +45,7 @@ parentheses. - **OutVariable** (ov) - **OutBuffer** (ob) - **PipelineVariable** (pv) +- **ProgressAction** (proga) - **Verbose** (vb) - **WarningAction** (wa) - **WarningVariable** (wv) @@ -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 diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md index f2ba790f3bcc..9baa252beee0 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md @@ -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 @@ -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 @@ -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. @@ -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: @@ -227,7 +226,7 @@ function Get-Sample { [CmdletBinding()] param([string]$Name, [string]$Path) - DynamicParam + dynamicparam { if ($Path.StartsWith("HKLM:")) { @@ -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 @@ -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 Tab after the parameter name. diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_Functions_CmdletBindingAttribute.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_Functions_CmdletBindingAttribute.md index 3ad708f6c580..804b99b62793 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_Functions_CmdletBindingAttribute.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_Functions_CmdletBindingAttribute.md @@ -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 @@ -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 @@ -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 @@ -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 @@ -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] + + +[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 diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_PSCustomObject.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_PSCustomObject.md index fd13f2696783..5a458b43cdeb 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_PSCustomObject.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_PSCustomObject.md @@ -1,7 +1,7 @@ --- description: Explains the differences between the [psobject] and [pscustomobject] type accelerators. Locale: en-US -ms.date: 10/11/2023 +ms.date: 07/02/2024 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_pscustomobject?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 title: about PSCustomObject @@ -187,7 +187,7 @@ While, casting an object to `[psobject]` appears to have no affect on the type, PowerShell adds an _invisible_ `[psobject]` wrapper around the object. This can have subtle side effects. -- Wrapped objects will match their original type and the `[psobject]` type. +- Wrapped objects match their original type and the `[psobject]` type. ```powershell PS> 1 -is [Int32] @@ -209,13 +209,53 @@ have subtle side effects. PS> '{0} {1}' -f ([psobject] (1, 2)) Error formatting a string: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.. - At line:1 char:1 - + '{0} {1}' -f ([psobject] (1, 2)) - + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - + CategoryInfo : InvalidOperation: ({0} {1}:String) [], RuntimeException - + FullyQualifiedErrorId : FormatError ``` +## Conversion of hashtables containing similar keys + +Case-sensitive dictionaries might contain key names that only differ by case. +When you cast such a dictionary to a `[pscustomobject]`, PowerShell preserves +that case of the keys but isn't case-sensitive. As a result: + +- The case of the first duplicate key becomes the name of that key. +- The value of the last case-variant key becomes the property value. + +The following example demonstrates this behavior: + +```powershell +$OrderedHashTable = [System.Collections.Specialized.OrderedDictionary]::new() +$OrderedHashTable['One'] = 1 +$OrderedHashTable['TWO'] = 2 +$OrderedHashTable['two'] = 3 # case variation +$OrderedHashTable['Three'] = 3 +$OrderedHashTable +``` + +Notice that the ordered hashtable contains multiple keys that differ only by +case. + +```Output +Name Value +---- ----- +One 1 +TWO 2 +two 3 +Three 3 +``` + +When that hashtable is cast to a `[pscustomobject]`, the case of the name of +first key is used, but that value of the last matching key name is used. + +```powershell +[PSCustomObject]$OrderedHashTable +``` + +```Output +One TWO Three +--- --- ----- + 1 3 3 +``` + ## Notes In Windows PowerShell, objects created by casting a **Hashtable** to diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_Reserved_Words.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_Reserved_Words.md index ce6ad3cadeff..3f2a84ef71dd 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_Reserved_Words.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_Reserved_Words.md @@ -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 @@ -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 diff --git a/reference/7.2/Microsoft.PowerShell.Core/About/about_CommonParameters.md b/reference/7.2/Microsoft.PowerShell.Core/About/about_CommonParameters.md index 425cf748d8e0..6d453fe259f7 100644 --- a/reference/7.2/Microsoft.PowerShell.Core/About/about_CommonParameters.md +++ b/reference/7.2/Microsoft.PowerShell.Core/About/about_CommonParameters.md @@ -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 @@ -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 @@ -43,6 +45,7 @@ parentheses. - **OutVariable** (ov) - **OutBuffer** (ob) - **PipelineVariable** (pv) +- **ProgressAction** (proga) - **Verbose** (vb) - **WarningAction** (wa) - **WarningVariable** (wv) @@ -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 diff --git a/reference/7.2/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md b/reference/7.2/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md index 60991f9e5a9b..3ee1723f4601 100644 --- a/reference/7.2/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md +++ b/reference/7.2/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md @@ -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 @@ -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 @@ -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. @@ -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: @@ -222,7 +221,7 @@ function Get-Sample { [CmdletBinding()] param([string]$Name, [string]$Path) - DynamicParam + dynamicparam { if ($Path.StartsWith("HKLM:")) { @@ -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 @@ -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 Tab after the parameter name. @@ -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. @@ -1250,7 +1250,7 @@ intended for external usage. - [about_Functions_OutputTypeAttribute][13] -[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 diff --git a/reference/7.2/Microsoft.PowerShell.Core/About/about_Functions_CmdletBindingAttribute.md b/reference/7.2/Microsoft.PowerShell.Core/About/about_Functions_CmdletBindingAttribute.md index 565184b58115..fc7b8c6b934c 100644 --- a/reference/7.2/Microsoft.PowerShell.Core/About/about_Functions_CmdletBindingAttribute.md +++ b/reference/7.2/Microsoft.PowerShell.Core/About/about_Functions_CmdletBindingAttribute.md @@ -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-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 title: about Functions CmdletBindingAttribute @@ -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 @@ -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 @@ -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 @@ -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] + + +[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 diff --git a/reference/7.2/Microsoft.PowerShell.Core/About/about_PSCustomObject.md b/reference/7.2/Microsoft.PowerShell.Core/About/about_PSCustomObject.md index 0bd6e7544bc4..fe86e1141164 100644 --- a/reference/7.2/Microsoft.PowerShell.Core/About/about_PSCustomObject.md +++ b/reference/7.2/Microsoft.PowerShell.Core/About/about_PSCustomObject.md @@ -1,7 +1,7 @@ --- description: Explains the differences between the [psobject] and [pscustomobject] type accelerators. Locale: en-US -ms.date: 10/11/2023 +ms.date: 07/02/2024 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_PSCustomObject?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 title: about PSCustomObject @@ -186,8 +186,7 @@ While, casting an object to `[psobject]` appears to have no affect on the type, PowerShell adds an _invisible_ `[psobject]` wrapper around the object. This can have subtle side effects. -- Wrapped objects will match their original type and the - `[psobject]` type. +- Wrapped objects match their original type and the `[psobject]` type. ```powershell PS> 1 -is [Int32] @@ -211,6 +210,57 @@ have subtle side effects. to zero and less than the size of the argument list.. ``` +## Conversion of hashtables containing similar keys + +Case-sensitive dictionaries might contain key names that only differ by case. +When you cast such a dictionary to a `[pscustomobject]`, PowerShell preserves +that case of the keys but isn't case-sensitive. As a result: + +- The case of the first duplicate key becomes the name of that key. +- The value of the last case-variant key becomes the property value. + +The following example demonstrates this behavior: + +```powershell +$Json = '{ + "One": 1, + "two": 2, + "Two": 3, + "three": 3, + "Three": 4, + "THREE": 5 +}' +$OrderedHashTable = $Json | ConvertFrom-Json -AsHashTable +$OrderedHashTable +``` + +Notice that the ordered hashtable contains multiple keys that differ only by +case. + +```Output +Name Value +---- ----- +One 1 +two 2 +Two 3 +three 3 +Three 4 +THREE 5 +``` + +When that hashtable is cast to a `[pscustomobject]`, the case of the name of +first key is used, but that value of the last matching key name is used. + +```powershell +[PSCustomObject]$OrderedHashTable +``` + +```Output +One two three +--- --- ----- + 1 3 5 +``` + ## Notes In Windows PowerShell, objects created by casting a **Hashtable** to diff --git a/reference/7.2/Microsoft.PowerShell.Core/About/about_Reserved_Words.md b/reference/7.2/Microsoft.PowerShell.Core/About/about_Reserved_Words.md index f98bcc05d3f8..ef006a8b6bb6 100644 --- a/reference/7.2/Microsoft.PowerShell.Core/About/about_Reserved_Words.md +++ b/reference/7.2/Microsoft.PowerShell.Core/About/about_Reserved_Words.md @@ -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-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 title: about Reserved Words @@ -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 diff --git a/reference/7.4/Microsoft.PowerShell.Core/About/about_CommonParameters.md b/reference/7.4/Microsoft.PowerShell.Core/About/about_CommonParameters.md index 97d8ecfcfb53..404778b58324 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/About/about_CommonParameters.md +++ b/reference/7.4/Microsoft.PowerShell.Core/About/about_CommonParameters.md @@ -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.4&WT.mc_id=ps-gethelp schema: 2.0.0 @@ -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 @@ -245,7 +247,7 @@ Accept wildcard characters: False ### -InformationVariable Introduced in PowerShell 5.0. When you use the **InformationVariable** common -parameter, information records are stored in the variable specify by the +parameter, information records are stored in the variable specified by the parameter. And PowerShell cmdlet can write information records to the **Information** stream. You can also use the `Write-Information` cmdlet to write information records. @@ -462,7 +464,8 @@ temp 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. +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`, diff --git a/reference/7.4/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md b/reference/7.4/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md index 52deeac701ea..2edbb72d9747 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md +++ b/reference/7.4/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md @@ -1,7 +1,7 @@ --- description: Explains how to add parameters to advanced functions. Locale: en-US -ms.date: 01/31/2024 +ms.date: 07/02/2024 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-7.4&WT.mc_id=ps-gethelp schema: 2.0.0 title: about Functions Advanced Parameters @@ -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 diff --git a/reference/7.4/Microsoft.PowerShell.Core/About/about_Functions_CmdletBindingAttribute.md b/reference/7.4/Microsoft.PowerShell.Core/About/about_Functions_CmdletBindingAttribute.md index 520faedfbcd5..83e2231ca084 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/About/about_Functions_CmdletBindingAttribute.md +++ b/reference/7.4/Microsoft.PowerShell.Core/About/about_Functions_CmdletBindingAttribute.md @@ -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-7.4&WT.mc_id=ps-gethelp schema: 2.0.0 title: about Functions CmdletBindingAttribute @@ -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 @@ -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 @@ -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 @@ -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] + + +[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 diff --git a/reference/7.4/Microsoft.PowerShell.Core/About/about_PSCustomObject.md b/reference/7.4/Microsoft.PowerShell.Core/About/about_PSCustomObject.md index 6c2fa2541286..669676b9ac33 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/About/about_PSCustomObject.md +++ b/reference/7.4/Microsoft.PowerShell.Core/About/about_PSCustomObject.md @@ -1,7 +1,7 @@ --- description: Explains the differences between the [psobject] and [pscustomobject] type accelerators. Locale: en-US -ms.date: 10/11/2023 +ms.date: 07/02/2024 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_pscustomobject?view=powershell-7.4&WT.mc_id=ps-gethelp schema: 2.0.0 title: about PSCustomObject @@ -186,8 +186,7 @@ While, casting an object to `[psobject]` appears to have no affect on the type, PowerShell adds an _invisible_ `[psobject]` wrapper around the object. This can have subtle side effects. -- Wrapped objects will match their original type and the - `[psobject]` type. +- Wrapped objects match their original type and the `[psobject]` type. ```powershell PS> 1 -is [Int32] @@ -211,6 +210,57 @@ have subtle side effects. to zero and less than the size of the argument list.. ``` +## Conversion of hashtables containing similar keys + +Case-sensitive dictionaries might contain key names that only differ by case. +When you cast such a dictionary to a `[pscustomobject]`, PowerShell preserves +that case of the keys but isn't case-sensitive. As a result: + +- The case of the first duplicate key becomes the name of that key. +- The value of the last case-variant key becomes the property value. + +The following example demonstrates this behavior: + +```powershell +$Json = '{ + "One": 1, + "two": 2, + "Two": 3, + "three": 3, + "Three": 4, + "THREE": 5 +}' +$OrderedHashTable = $Json | ConvertFrom-Json -AsHashTable +$OrderedHashTable +``` + +Notice that the ordered hashtable contains multiple keys that differ only by +case. + +```Output +Name Value +---- ----- +One 1 +two 2 +Two 3 +three 3 +Three 4 +THREE 5 +``` + +When that hashtable is cast to a `[pscustomobject]`, the case of the name of +first key is used, but that value of the last matching key name is used. + +```powershell +[PSCustomObject]$OrderedHashTable +``` + +```Output +One two three +--- --- ----- + 1 3 5 +``` + ## Notes In Windows PowerShell, objects created by casting a **Hashtable** to diff --git a/reference/7.4/Microsoft.PowerShell.Core/About/about_Reserved_Words.md b/reference/7.4/Microsoft.PowerShell.Core/About/about_Reserved_Words.md index 36e48f69fdc1..a17d9299f099 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/About/about_Reserved_Words.md +++ b/reference/7.4/Microsoft.PowerShell.Core/About/about_Reserved_Words.md @@ -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-7.4&WT.mc_id=ps-gethelp schema: 2.0.0 title: about Reserved Words @@ -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 diff --git a/reference/7.5/Microsoft.PowerShell.Core/About/about_CommonParameters.md b/reference/7.5/Microsoft.PowerShell.Core/About/about_CommonParameters.md index df621bd127c2..a362c52e0bc6 100644 --- a/reference/7.5/Microsoft.PowerShell.Core/About/about_CommonParameters.md +++ b/reference/7.5/Microsoft.PowerShell.Core/About/about_CommonParameters.md @@ -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.5&WT.mc_id=ps-gethelp schema: 2.0.0 @@ -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 @@ -245,7 +247,7 @@ Accept wildcard characters: False ### -InformationVariable Introduced in PowerShell 5.0. When you use the **InformationVariable** common -parameter, information records are stored in a variable specified by the +parameter, information records are stored in the variable specified by the parameter. And PowerShell cmdlet can write information records to the **Information** stream. You can also use the `Write-Information` cmdlet to write information records. @@ -462,7 +464,8 @@ temp 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. +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`, diff --git a/reference/7.5/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md b/reference/7.5/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md index a4e7d07cf818..767ca945ed2f 100644 --- a/reference/7.5/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md +++ b/reference/7.5/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md @@ -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.5&WT.mc_id=ps-gethelp schema: 2.0.0 title: about Functions Advanced Parameters @@ -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 @@ -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. @@ -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: @@ -222,7 +221,7 @@ function Get-Sample { [CmdletBinding()] param([string]$Name, [string]$Path) - DynamicParam + dynamicparam { if ($Path.StartsWith("HKLM:")) { @@ -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 @@ -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 Tab after the parameter name. @@ -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. @@ -1273,7 +1273,7 @@ intended for external usage. - [about_Functions_OutputTypeAttribute][13] -[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 diff --git a/reference/7.5/Microsoft.PowerShell.Core/About/about_Functions_CmdletBindingAttribute.md b/reference/7.5/Microsoft.PowerShell.Core/About/about_Functions_CmdletBindingAttribute.md index 5aed9bf7788a..eb5212b7c079 100644 --- a/reference/7.5/Microsoft.PowerShell.Core/About/about_Functions_CmdletBindingAttribute.md +++ b/reference/7.5/Microsoft.PowerShell.Core/About/about_Functions_CmdletBindingAttribute.md @@ -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-7.5&WT.mc_id=ps-gethelp schema: 2.0.0 title: about Functions CmdletBindingAttribute @@ -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 @@ -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 @@ -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 @@ -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] + + +[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 diff --git a/reference/7.5/Microsoft.PowerShell.Core/About/about_PSCustomObject.md b/reference/7.5/Microsoft.PowerShell.Core/About/about_PSCustomObject.md index a7bc7fe193cf..de55e85f806a 100644 --- a/reference/7.5/Microsoft.PowerShell.Core/About/about_PSCustomObject.md +++ b/reference/7.5/Microsoft.PowerShell.Core/About/about_PSCustomObject.md @@ -186,8 +186,7 @@ While, casting an object to `[psobject]` appears to have no affect on the type, PowerShell adds an _invisible_ `[psobject]` wrapper around the object. This can have subtle side effects. -- Wrapped objects will match their original type and the - `[psobject]` type. +- Wrapped objects match their original type and the `[psobject]` type. ```powershell PS> 1 -is [Int32] @@ -211,6 +210,57 @@ have subtle side effects. to zero and less than the size of the argument list.. ``` +## Conversion of hashtables containing similar keys + +Case-sensitive dictionaries might contain key names that only differ by case. +When you cast such a dictionary to a `[pscustomobject]`, PowerShell preserves +that case of the keys but isn't case-sensitive. As a result: + +- The case of the first duplicate key becomes the name of that key. +- The value of the last case-variant key becomes the property value. + +The following example demonstrates this behavior: + +```powershell +$Json = '{ + "One": 1, + "two": 2, + "Two": 3, + "three": 3, + "Three": 4, + "THREE": 5 +}' +$OrderedHashTable = $Json | ConvertFrom-Json -AsHashTable +$OrderedHashTable +``` + +Notice that the ordered hashtable contains multiple keys that differ only by +case. + +```Output +Name Value +---- ----- +One 1 +two 2 +Two 3 +three 3 +Three 4 +THREE 5 +``` + +When that hashtable is cast to a `[pscustomobject]`, the case of the name of +first key is used, but that value of the last matching key name is used. + +```powershell +[PSCustomObject]$OrderedHashTable +``` + +```Output +One two three +--- --- ----- + 1 3 5 +``` + ## Notes In Windows PowerShell, objects created by casting a **Hashtable** to diff --git a/reference/7.5/Microsoft.PowerShell.Core/About/about_Reserved_Words.md b/reference/7.5/Microsoft.PowerShell.Core/About/about_Reserved_Words.md index 7227543f4e25..0b3ad902f86f 100644 --- a/reference/7.5/Microsoft.PowerShell.Core/About/about_Reserved_Words.md +++ b/reference/7.5/Microsoft.PowerShell.Core/About/about_Reserved_Words.md @@ -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-7.5&WT.mc_id=ps-gethelp schema: 2.0.0 title: about Reserved Words @@ -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