11---
22description : Describes how to use splatting to pass parameters to commands in PowerShell.
33Locale : en-US
4- ms.date : 12/12/2022
4+ ms.date : 01/29/2024
55online version : https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-7.2&WT.mc_id=ps-gethelp
66schema : 2.0.0
77title : about Splatting
@@ -274,6 +274,26 @@ foreach ($vm in $allVms)
274274}
275275```
276276
277+ ### Example 4: Using multiple splatted objects in a single command
278+
279+ You can use multiple splatted objects in a single command. In this example,
280+ different parameters are defined in separate hashtables. The hashtables are
281+ splatted in a single ` Write-Host ` command.
282+
283+ ``` powershell
284+ $a = @{
285+ Message = 'Hello', 'World!'
286+ }
287+ $b = @{
288+ Separator = '|'
289+ }
290+ $c = @{
291+ BackgroundColor = 'Cyan'
292+ ForegroundColor = 'Black'
293+ }
294+ Write-Host @a @b @c
295+ ```
296+
277297## Splatting command parameters
278298
279299You can use splatting to represent the parameters of a command. This technique
@@ -333,13 +353,15 @@ Get-MyCommand -P -C -Name PowerShell
333353```
334354
335355``` Output
336- Handles NPM(K) PM(K ) WS(K) VM( M) CPU(s) Id ProcessName
337- ------- ------ ----- ----- ----- ------ -- -----------
338- 408 28 75568 83176 620 1.33 1692 powershell
356+ NPM(K) PM(M ) WS(M) CPU(s) Id SI ProcessName
357+ ------ ----- ----- ------ -- -- -----------
358+ 50 112.76 78.52 16.64 6880 1 powershell
339359
340- Path : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.e
360+ Path : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
341361Extension : .exe
342- Definition : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.e
362+ Definition : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
363+ Source : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
364+ Version : 10.0.22621.3085
343365Visibility : Public
344366OutputType : {System.String}
345367Name : powershell.exe
@@ -350,14 +372,13 @@ RemotingCapability : PowerShell
350372Parameters :
351373ParameterSets :
352374HelpUri :
353- FileVersionInfo : File: C:\Windows\System32\WindowsPowerShell
354- \v1.0\powershell.exe
375+ FileVersionInfo : File: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
355376 InternalName: POWERSHELL
356377 OriginalFilename: PowerShell.EXE.MUI
357- FileVersion: 10.0.14393.0 (rs1_release.160715-1616
378+ FileVersion: 10.0.22621.1 (WinBuild.160101.0800)
358379 FileDescription: Windows PowerShell
359- Product: Microsoft Windows Operating System
360- ProductVersion: 10.0.14393.0
380+ Product: Microsoft® Windows® Operating System
381+ ProductVersion: 10.0.22621.1
361382 Debug: False
362383 Patched: False
363384 PreRelease: False
@@ -375,11 +396,18 @@ parameter definition.
375396
376397PowerShell Desired State Configuration (DSC) was not designed to use splatting.
377398You cannot use splatting to pass values into a DSC resource. For more
378- information, see Gael Colas' article [ Pseudo-Splatting DSC Resources] ( https://gaelcolas.com/2017/11/05/pseudo-splatting-dsc-resources/ ) .
399+ information, see Gael Colas' article [ Pseudo-Splatting DSC Resources] [ 05 ] .
379400
380401## See also
381402
382- - [ about_Arrays] ( about_Arrays.md )
383- - [ about_Automatic_Variables] ( about_Automatic_Variables.md )
384- - [ about_Hash_Tables] ( about_Hash_Tables.md )
385- - [ about_Parameters] ( about_Parameters.md )
403+ - [ about_Arrays] [ 01 ]
404+ - [ about_Automatic_Variables] [ 02 ]
405+ - [ about_Hash_Tables] [ 03 ]
406+ - [ about_Parameters] [ 04 ]
407+
408+ <!-- link references -->
409+ [ 01 ] : about_Arrays.md
410+ [ 02 ] : about_Automatic_Variables.md
411+ [ 03 ] : about_Hash_Tables.md
412+ [ 04 ] : about_Parameters.md
413+ [ 05 ] : https://gaelcolas.com/2017/11/05/pseudo-splatting-dsc-resources/
0 commit comments