diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_Splatting.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_Splatting.md index 2783f756404..70404af1ace 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_Splatting.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_Splatting.md @@ -1,7 +1,7 @@ --- description: Describes how to use splatting to pass parameters to commands in PowerShell. Locale: en-US -ms.date: 01/18/2026 +ms.date: 06/17/2026 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 title: about_Splatting @@ -112,6 +112,47 @@ $ArrayArguments = "test.txt", "test2.txt" Copy-Item @ArrayArguments -WhatIf ``` +A jagged array is an array that contains other arrays. PowerShell handles +splatting of jagged arrays for native commands differently than for PowerShell +commands. + +For example, the following command splats a jagged array to a PowerShell +script. + +```powershell +$arguments = 1, (2, 3), 4 +D:\temp\testargs.ps1 @arguments +``` + +The script receives three arguments, the second of which is an array. + +```Output +3 argument(s) received (enclosed in <...> for delineation): + + <1> + <2 3> + <4> +``` + +In this example, the jagged array is splatted to a native command. + +```powershell +$arguments = 1, (2, 3), 4 +echoargs.exe @arguments +``` + +The native command receives four arguments, the second and third items are +the elements of the inner array. + +```Output +4 argument(s) received (enclosed in <...> for delineation): + + <1> + <2> + <3> + <4> +``` + ### Using the ArgumentList parameter Several cmdlets have an **ArgumentList** parameter that is used to pass diff --git a/reference/7.4/Microsoft.PowerShell.Core/About/about_Splatting.md b/reference/7.4/Microsoft.PowerShell.Core/About/about_Splatting.md index 29ddff1c039..3419455aed4 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/About/about_Splatting.md +++ b/reference/7.4/Microsoft.PowerShell.Core/About/about_Splatting.md @@ -1,7 +1,7 @@ --- description: Describes how to use splatting to pass parameters to commands in PowerShell. Locale: en-US -ms.date: 01/18/2026 +ms.date: 06/17/2026 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-7.4&WT.mc_id=ps-gethelp schema: 2.0.0 title: about_Splatting @@ -115,6 +115,47 @@ $ArrayArguments = "test.txt", "test2.txt" Copy-Item @ArrayArguments -WhatIf ``` +A jagged array is an array that contains other arrays. PowerShell handles +splatting of jagged arrays for native commands differently than for PowerShell +commands. + +For example, the following command splats a jagged array to a PowerShell +script. + +```powershell +$arguments = 1, (2, 3), 4 +D:\temp\testargs.ps1 @arguments +``` + +The script receives three arguments, the second of which is an array. + +```Output +3 argument(s) received (enclosed in <...> for delineation): + + <1> + <2 3> + <4> +``` + +In this example, the jagged array is splatted to a native command. + +```powershell +$arguments = 1, (2, 3), 4 +echoargs.exe @arguments +``` + +The native command receives four arguments, the second and third items are +the elements of the inner array. + +```Output +4 argument(s) received (enclosed in <...> for delineation): + + <1> + <2> + <3> + <4> +``` + ### Using the ArgumentList parameter Several cmdlets have an **ArgumentList** parameter that is used to pass diff --git a/reference/7.5/Microsoft.PowerShell.Core/About/about_Splatting.md b/reference/7.5/Microsoft.PowerShell.Core/About/about_Splatting.md index e37d4cf06b4..d466e0c71b8 100644 --- a/reference/7.5/Microsoft.PowerShell.Core/About/about_Splatting.md +++ b/reference/7.5/Microsoft.PowerShell.Core/About/about_Splatting.md @@ -1,7 +1,7 @@ --- description: Describes how to use splatting to pass parameters to commands in PowerShell. Locale: en-US -ms.date: 01/18/2026 +ms.date: 06/17/2026 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-7.5&WT.mc_id=ps-gethelp schema: 2.0.0 title: about_Splatting @@ -115,6 +115,47 @@ $ArrayArguments = "test.txt", "test2.txt" Copy-Item @ArrayArguments -WhatIf ``` +A jagged array is an array that contains other arrays. PowerShell handles +splatting of jagged arrays for native commands differently than for PowerShell +commands. + +For example, the following command splats a jagged array to a PowerShell +script. + +```powershell +$arguments = 1, (2, 3), 4 +D:\temp\testargs.ps1 @arguments +``` + +The script receives three arguments, the second of which is an array. + +```Output +3 argument(s) received (enclosed in <...> for delineation): + + <1> + <2 3> + <4> +``` + +In this example, the jagged array is splatted to a native command. + +```powershell +$arguments = 1, (2, 3), 4 +echoargs.exe @arguments +``` + +The native command receives four arguments, the second and third items are +the elements of the inner array. + +```Output +4 argument(s) received (enclosed in <...> for delineation): + + <1> + <2> + <3> + <4> +``` + ### Using the ArgumentList parameter Several cmdlets have an **ArgumentList** parameter that is used to pass diff --git a/reference/7.6/Microsoft.PowerShell.Core/About/about_Splatting.md b/reference/7.6/Microsoft.PowerShell.Core/About/about_Splatting.md index 56603090cfb..7f1fc43c310 100644 --- a/reference/7.6/Microsoft.PowerShell.Core/About/about_Splatting.md +++ b/reference/7.6/Microsoft.PowerShell.Core/About/about_Splatting.md @@ -1,7 +1,7 @@ --- description: Describes how to use splatting to pass parameters to commands in PowerShell. Locale: en-US -ms.date: 01/18/2026 +ms.date: 06/17/2026 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-7.6&WT.mc_id=ps-gethelp schema: 2.0.0 title: about_Splatting @@ -115,6 +115,47 @@ $ArrayArguments = "test.txt", "test2.txt" Copy-Item @ArrayArguments -WhatIf ``` +A jagged array is an array that contains other arrays. PowerShell handles +splatting of jagged arrays for native commands differently than for PowerShell +commands. + +For example, the following command splats a jagged array to a PowerShell +script. + +```powershell +$arguments = 1, (2, 3), 4 +D:\temp\testargs.ps1 @arguments +``` + +The script receives three arguments, the second of which is an array. + +```Output +3 argument(s) received (enclosed in <...> for delineation): + + <1> + <2 3> + <4> +``` + +In this example, the jagged array is splatted to a native command. + +```powershell +$arguments = 1, (2, 3), 4 +echoargs.exe @arguments +``` + +The native command receives four arguments, the second and third items are +the elements of the inner array. + +```Output +4 argument(s) received (enclosed in <...> for delineation): + + <1> + <2> + <3> + <4> +``` + ### Using the ArgumentList parameter Several cmdlets have an **ArgumentList** parameter that is used to pass diff --git a/reference/7.7/Microsoft.PowerShell.Core/About/about_Splatting.md b/reference/7.7/Microsoft.PowerShell.Core/About/about_Splatting.md index 0c73a262062..7115827122b 100644 --- a/reference/7.7/Microsoft.PowerShell.Core/About/about_Splatting.md +++ b/reference/7.7/Microsoft.PowerShell.Core/About/about_Splatting.md @@ -1,7 +1,7 @@ --- description: Describes how to use splatting to pass parameters to commands in PowerShell. Locale: en-US -ms.date: 01/18/2026 +ms.date: 06/17/2026 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-7.7&WT.mc_id=ps-gethelp schema: 2.0.0 title: about_Splatting @@ -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 @@ -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 @@ -115,6 +115,47 @@ $ArrayArguments = "test.txt", "test2.txt" Copy-Item @ArrayArguments -WhatIf ``` +A jagged array is an array that contains other arrays. PowerShell handles +splatting of jagged arrays for native commands differently than for PowerShell +commands. + +For example, the following command splats a jagged array to a PowerShell +script. + +```powershell +$arguments = 1, (2, 3), 4 +D:\temp\testargs.ps1 @arguments +``` + +The script receives three arguments, the second of which is an array. + +```Output +3 argument(s) received (enclosed in <...> for delineation): + + <1> + <2 3> + <4> +``` + +In this example, the jagged array is splatted to a native command. + +```powershell +$arguments = 1, (2, 3), 4 +echoargs.exe @arguments +``` + +The native command receives four arguments, the second and third items are +the elements of the inner array. + +```Output +4 argument(s) received (enclosed in <...> for delineation): + + <1> + <2> + <3> + <4> +``` + ### Using the ArgumentList parameter Several cmdlets have an **ArgumentList** parameter that is used to pass