- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use Hashtable splatting in PowerShell?
Splatting is the way to pass the collection of the parameters to the command as a single value. It uses the Hashtable splatting means that we can pass the Name and Value pair combination. We can use the named positional parameter for this with the values we want to provide.
For example,
First, we will check how we run the Copy-Item command here without splatting,
$params = @{ Path = 'C:\Temp\25Aug2020.txt' Destination = 'C:\test1' Verbose = $true Force = $true } Copy-Item @params
Another Example,
$hash = @{ From = 'harris@Microsoftmail.com' To = 'Jacob@MicrosoftMail.com' SMTP = 'smtp.microsoftmail.com' Priority = 'High' } Send-MailMessage @Hash -Subject 'Test Email'
In the above example, we are passing the splatted hash and separate Subject parameter in the command.
- Related Articles
- How to use Array Splatting in PowerShell?
- What is splatting in PowerShell?
- How to convert Dictionary to Hashtable in PowerShell?
- How to add multiple values in the Hashtable using PowerShell?
- How to convert command output to the Hashtable format in PowerShell?
- How to convert JSON object to Hashtable format using PowerShell?
- How to convert the hashtable to the JSON format using PowerShell?
- How to use stopwatch in PowerShell?
- How to use PowerShell as a Calculator? Or How to use PowerShell for arithmetic operations?
- How to use Measure-Object in PowerShell?
- How to use Wait-Process in Powershell?
- How to use function Alias in PowerShell?
- How to use a transcript in PowerShell?
- How to use Compare-Object in PowerShell?
- What is the difference between Dictionary and HashTable in PowerShell?

Advertisements