
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is Splatting in PowerShell
PowerShell splatting is a method to pass the collection of the parameters as a single command unit which makes the command shorter and easier for the user to read commands. Splatting uses the symbol (@) instead of ($) which tells the user that splatting is used and PowerShell is passing a set of values instead of a single value.
Splatting in PowerShell was included from the v3.0 onwards and you can pass all parameters in the command.
For example,
$params = @{ Path = 'C:\Temp\25Aug2020.txt' Destination = 'C:\test1' Verbose = $true Force = $true } Copy-Item @params
The splatting parameters can be used with Hashtable and with an Array.
Hashtable splatting is a combination of the Name and value pair. You can use this format for all parameter types, including Positional and Switch parameters. Positional parameters must be assigned by name.
Array Splatting uses values of the positional parameter, which do not require parameter names. The values must be in the positional number order in an array.
Positional parameters can be identified with the Help command. For example, to identify the Copy-Item positional parameters, use the below command.
help Copy-Item -Parameter *