Skip to content

Commit 6abadc4

Browse files
authored
Fix typo and add multi-splat example (#10836)
1 parent fbc493b commit 6abadc4

File tree

10 files changed

+230
-90
lines changed

10 files changed

+230
-90
lines changed

reference/5.1/Microsoft.PowerShell.Core/About/about_Splatting.md

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes how to use splatting to pass parameters to commands in PowerShell.
33
Locale: en-US
4-
ms.date: 12/12/2022
4+
ms.date: 01/29/2024
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-5.1&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about Splatting
@@ -231,6 +231,26 @@ b = 2
231231
c = 3
232232
```
233233

234+
### Example 3: Using multiple splatted objects in a single command
235+
236+
You can use multiple splatted objects in a single command. In this example,
237+
different parameters are defined in separate hashtables. The hashtables are
238+
splatted in a single `Write-Host` command.
239+
240+
```powershell
241+
$a = @{
242+
Message = 'Hello', 'World!'
243+
}
244+
$b = @{
245+
Separator = '|'
246+
}
247+
$c = @{
248+
BackgroundColor = 'Cyan'
249+
ForegroundColor = 'Black'
250+
}
251+
Write-Host @a @b @c
252+
```
253+
234254
## Splatting command parameters
235255

236256
You can use splatting to represent the parameters of a command. This technique
@@ -290,13 +310,15 @@ Get-MyCommand -P -C -Name PowerShell
290310
```
291311

292312
```Output
293-
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
294-
------- ------ ----- ----- ----- ------ -- -----------
295-
408 28 75568 83176 620 1.33 1692 powershell
313+
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
314+
------- ------ ----- ----- ------ -- -- -----------
315+
830 50 115840 95524 16.75 6880 1 powershell
296316
297-
Path : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.e
317+
Path : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
298318
Extension : .exe
299-
Definition : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.e
319+
Definition : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
320+
Source : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
321+
Version : 10.0.22621.3085
300322
Visibility : Public
301323
OutputType : {System.String}
302324
Name : powershell.exe
@@ -307,14 +329,13 @@ RemotingCapability : PowerShell
307329
Parameters :
308330
ParameterSets :
309331
HelpUri :
310-
FileVersionInfo : File: C:\Windows\System32\WindowsPowerShell
311-
\v1.0\powershell.exe
332+
FileVersionInfo : File: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
312333
InternalName: POWERSHELL
313334
OriginalFilename: PowerShell.EXE.MUI
314-
FileVersion: 10.0.14393.0 (rs1_release.160715-1616
335+
FileVersion: 10.0.22621.1 (WinBuild.160101.0800)
315336
FileDescription: Windows PowerShell
316-
Product: Microsoft Windows Operating System
317-
ProductVersion: 10.0.14393.0
337+
Product: Microsoft® Windows® Operating System
338+
ProductVersion: 10.0.22621.1
318339
Debug: False
319340
Patched: False
320341
PreRelease: False
@@ -332,11 +353,18 @@ parameter definition.
332353

333354
PowerShell Desired State Configuration (DSC) was not designed to use splatting.
334355
You cannot use splatting to pass values into a DSC resource. For more
335-
information, see Gael Colas' article [Pseudo-Splatting DSC Resources](https://gaelcolas.com/2017/11/05/pseudo-splatting-dsc-resources/).
356+
information, see Gael Colas' article [Pseudo-Splatting DSC Resources][05].
336357

337358
## See also
338359

339-
- [about_Arrays](about_Arrays.md)
340-
- [about_Automatic_Variables](about_Automatic_Variables.md)
341-
- [about_Hash_Tables](about_Hash_Tables.md)
342-
- [about_Parameters](about_Parameters.md)
360+
- [about_Arrays][01]
361+
- [about_Automatic_Variables][02]
362+
- [about_Hash_Tables][03]
363+
- [about_Parameters][04]
364+
365+
<!-- link references -->
366+
[01]: about_Arrays.md
367+
[02]: about_Automatic_Variables.md
368+
[03]: about_Hash_Tables.md
369+
[04]: about_Parameters.md
370+
[05]: https://gaelcolas.com/2017/11/05/pseudo-splatting-dsc-resources/

reference/5.1/Microsoft.PowerShell.Management/New-Item.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Commands.Management.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Management
5-
ms.date: 06/30/2023
5+
ms.date: 01/29/2024
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/new-item?view=powershell-5.1&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
title: New-Item
@@ -221,7 +221,7 @@ Mode LastWriteTime Length Name
221221
### Example 9: Use the -Force parameter to overwrite existing files
222222

223223
This example creates a file with a value and then recreates the file using `-Force`. This overwrites
224-
The existing file and it will lose it's content as you can see by the length property
224+
the existing file, as you can see by the length property.
225225

226226
```powershell
227227
PS> New-Item ./TestFile.txt -ItemType File -Value 'This is just a test file'

reference/7.2/Microsoft.PowerShell.Core/About/about_Splatting.md

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes how to use splatting to pass parameters to commands in PowerShell.
33
Locale: en-US
4-
ms.date: 12/12/2022
4+
ms.date: 01/29/2024
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-7.2&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: 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

279299
You 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
341361
Extension : .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
343365
Visibility : Public
344366
OutputType : {System.String}
345367
Name : powershell.exe
@@ -350,14 +372,13 @@ RemotingCapability : PowerShell
350372
Parameters :
351373
ParameterSets :
352374
HelpUri :
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&reg; Windows&reg; Operating System
381+
ProductVersion: 10.0.22621.1
361382
Debug: False
362383
Patched: False
363384
PreRelease: False
@@ -375,11 +396,18 @@ parameter definition.
375396

376397
PowerShell Desired State Configuration (DSC) was not designed to use splatting.
377398
You 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/

reference/7.2/Microsoft.PowerShell.Management/New-Item.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Commands.Management.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Management
5-
ms.date: 06/30/2023
5+
ms.date: 01/29/2024
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/new-item?view=powershell-7.2&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
title: New-Item
@@ -221,7 +221,7 @@ Mode LastWriteTime Length Name
221221
### Example 9: Use the -Force parameter to overwrite existing files
222222

223223
This example creates a file with a value and then recreates the file using `-Force`. This overwrites
224-
The existing file and it will lose it's content as you can see by the length property
224+
the existing file, as you can see by the length property.
225225

226226
```powershell
227227
PS> New-Item ./TestFile.txt -ItemType File -Value 'This is just a test file'

reference/7.3/Microsoft.PowerShell.Core/About/about_Splatting.md

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes how to use splatting to pass parameters to commands in PowerShell.
33
Locale: en-US
4-
ms.date: 12/12/2022
4+
ms.date: 01/29/2024
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-7.3&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: 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

279299
You 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
341361
Extension : .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
343365
Visibility : Public
344366
OutputType : {System.String}
345367
Name : powershell.exe
@@ -350,14 +372,13 @@ RemotingCapability : PowerShell
350372
Parameters :
351373
ParameterSets :
352374
HelpUri :
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&reg; Windows&reg; Operating System
381+
ProductVersion: 10.0.22621.1
361382
Debug: False
362383
Patched: False
363384
PreRelease: False
@@ -375,11 +396,18 @@ parameter definition.
375396

376397
PowerShell Desired State Configuration (DSC) was not designed to use splatting.
377398
You 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/

reference/7.3/Microsoft.PowerShell.Management/New-Item.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Commands.Management.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Management
5-
ms.date: 06/30/2023
5+
ms.date: 01/29/2024
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/new-item?view=powershell-7.3&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
title: New-Item
@@ -221,7 +221,7 @@ Mode LastWriteTime Length Name
221221
### Example 9: Use the -Force parameter to overwrite existing files
222222

223223
This example creates a file with a value and then recreates the file using `-Force`. This overwrites
224-
The existing file and it will lose it's content as you can see by the length property
224+
the existing file, as you can see by the length property.
225225

226226
```powershell
227227
PS> New-Item ./TestFile.txt -ItemType File -Value 'This is just a test file'

0 commit comments

Comments
 (0)