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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 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
Expand Down Expand Up @@ -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

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: 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
Expand Down Expand Up @@ -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
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: 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
Expand Down Expand Up @@ -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
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: 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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions reference/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down