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 472a84a9a22..88ec2b4f554 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: 01/18/2026 +ms.date: 03/10/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 @@ -576,40 +576,36 @@ The `ValueFromRemainingArguments` argument indicates that the parameter accepts all the parameter's values in the command that aren't assigned to other parameters of the function. -There's a known issue for using collections with -**ValueFromRemainingArguments** where the passed-in collection is treated as a +Collections passed to **ValueFromRemainingArguments** are always treated as a single element. -The following example demonstrates this known issue. The **Remaining** -parameter should contain **one** at **index 0** and **two** at **index 1**. -Instead, both elements are combined into a single entity. - ```powershell function Test-Remainder { param( [Parameter(Mandatory, Position=0)] [string]$Value, - [Parameter(Position=1, ValueFromRemainingArguments)] + [Parameter(ValueFromRemainingArguments, Position=1)] [string[]]$Remaining ) - "Found $($Remaining.Count) elements" + "Value = $Value" + "Found $($Remaining.Count) remaining values" for ($i = 0; $i -lt $Remaining.Count; $i++) { "${i}: $($Remaining[$i])" } } -Test-Remainder first one, two ``` -```Output -Found 1 elements -0: one two -``` +```powershell +PS> Test-Remainder first one two, three -> [!NOTE] -> This issue is resolved in PowerShell 6.2. +Value = first +Found 2 remaining values +0: one +1: two three +``` #### HelpMessage argument 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 c1ece0adc25..7673a43ce83 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/18/2026 +ms.date: 03/10/2026 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 @@ -581,23 +581,54 @@ function Test-Remainder { [Parameter(Mandatory, Position=0)] [string]$Value, - [Parameter(Position=1, ValueFromRemainingArguments)] + [Parameter(ValueFromRemainingArguments, Position=1)] [string[]]$Remaining ) - "Found $($Remaining.Count) elements" + "Value = $Value" + "Found $($Remaining.Count) remaining values" for ($i = 0; $i -lt $Remaining.Count; $i++) { "${i}: $($Remaining[$i])" } } -Test-Remainder first one, two ``` -```Output -Found 2 elements +```powershell +PS> Test-Remainder first one two three + +Value = first +Found 3 remaining values 0: one 1: two +2: three +``` + +Beginning in PowerShell 6.2, collections are handled differently when passed to +**ValueFromRemainingArguments**. If you only pass a collection, then each value +in the collection is treated as a separate item. + +```powershell +PS> Test-Remainder first one, two, three + +Value = first +Found 3 remaining values +0: one +1: two +2: three +``` + +When you pass multiple values where at least one isn't a collection, the +collection is treated as a single item. + +```powershell +PS> Test-Remainder first one, two three four + +Value = first +Found 3 remaining values +0: one two +1: three +2: four ``` #### HelpMessage argument 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 e59e7f5dc0b..eb97af89660 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: 01/18/2026 +ms.date: 03/10/2026 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 @@ -581,23 +581,54 @@ function Test-Remainder { [Parameter(Mandatory, Position=0)] [string]$Value, - [Parameter(Position=1, ValueFromRemainingArguments)] + [Parameter(ValueFromRemainingArguments, Position=1)] [string[]]$Remaining ) - "Found $($Remaining.Count) elements" + "Value = $Value" + "Found $($Remaining.Count) remaining values" for ($i = 0; $i -lt $Remaining.Count; $i++) { "${i}: $($Remaining[$i])" } } -Test-Remainder first one, two ``` -```Output -Found 2 elements +```powershell +PS> Test-Remainder first one two three + +Value = first +Found 3 remaining values 0: one 1: two +2: three +``` + +Beginning in PowerShell 6.2, collections are handled differently when passed to +**ValueFromRemainingArguments**. If you only pass a collection, then each value +in the collection is treated as a separate item. + +```powershell +PS> Test-Remainder first one, two, three + +Value = first +Found 3 remaining values +0: one +1: two +2: three +``` + +When you pass multiple values where at least one isn't a collection, the +collection is treated as a single item. + +```powershell +PS> Test-Remainder first one, two three four + +Value = first +Found 3 remaining values +0: one two +1: three +2: four ``` #### HelpMessage argument diff --git a/reference/7.6/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md b/reference/7.6/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md index c5be2dda1a1..328cc07c5bc 100644 --- a/reference/7.6/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md +++ b/reference/7.6/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/18/2026 +ms.date: 03/10/2026 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-7.6&WT.mc_id=ps-gethelp schema: 2.0.0 title: about_Functions_Advanced_Parameters @@ -581,23 +581,54 @@ function Test-Remainder { [Parameter(Mandatory, Position=0)] [string]$Value, - [Parameter(Position=1, ValueFromRemainingArguments)] + [Parameter(ValueFromRemainingArguments, Position=1)] [string[]]$Remaining ) - "Found $($Remaining.Count) elements" + "Value = $Value" + "Found $($Remaining.Count) remaining values" for ($i = 0; $i -lt $Remaining.Count; $i++) { "${i}: $($Remaining[$i])" } } -Test-Remainder first one, two ``` -```Output -Found 2 elements +```powershell +PS> Test-Remainder first one two three + +Value = first +Found 3 remaining values 0: one 1: two +2: three +``` + +Beginning in PowerShell 6.2, collections are handled differently when passed to +**ValueFromRemainingArguments**. If you only pass a collection, then each value +in the collection is treated as a separate item. + +```powershell +PS> Test-Remainder first one, two, three + +Value = first +Found 3 remaining values +0: one +1: two +2: three +``` + +When you pass multiple values where at least one isn't a collection, the +collection is treated as a single item. + +```powershell +PS> Test-Remainder first one, two three four + +Value = first +Found 3 remaining values +0: one two +1: three +2: four ``` #### HelpMessage argument diff --git a/reference/index.yml b/reference/index.yml index 07786448a34..d618669863d 100644 --- a/reference/index.yml +++ b/reference/index.yml @@ -11,6 +11,7 @@ metadata: author: sdwheeler ms.author: sewhee ms.date: 03/18/2025 + no-loc: [Community, Discord, Slack, Spiceworks, "Stack Overflow" ] # highlightedContent section (optional) # Maximum of 8 items