Disclaimer
This is my personal blog. The opinions and views I express are my own. The information I provide is on an as-is basis. I make no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this blog and will not be liable for any errors, omissions, or delays in this information or any losses, injuries or damages arising from its use.

PowerShell Splatting How-To: I should use it more and so should you!

In my experience splatting is one of those often overlooked and underutilized features of PowerShell. Full disclosure, I don’t use it regularly myself. Most times I just forget it’s a thing.

For those that are new to PowerShell, splatting looks more difficult than it really is. The whole idea of this video is to demonstrate how easy splatting is, explain the syntax, and encourage its use.

Mark Kraus has already put together a more concise and detailed explanation on the subject here (https://get-powershellblog.blogspot.com/2019/11/teach-splating-or-die.html), I suggest you take a look. I particularly like Mark’s idea of “consider using splats for anything that uses 3 or more parameters”. I’m going to adopt this philosophy as my own best practice going forward.

If you have any questions leave them here, comment on the video or contact me on the twitter machine @signalwarrant.

3 Comments

  1. Jeffrey Leitheiser | | Reply

    Good Quick Tips… Eventually I will remember all these terms like “Splatting”. I love how this instruction is quick and to the point. Just like “GuyInACube” video’s.

  2. Joel Reed (@AKAJoelReed) | | Reply

    Great advice on using splatting. New-ADUser and other AD cmdlets are always somewhere I have used splatting as the sheer number of parameters gets daunting in scripts. However one additional bit of information in the $Params hashtable @{…} you do not need the semi-colon. PowerShell accepts it knowing that you intend to make this a collection of key value pairs but a simple carriage return new line is sufficient for PowerShell to create a valid hashtable. PowerShell is definitely “programming” but I always like to minimize the programmer-y feel of PowerShell.

    • David Hall | | Reply

      Good point Joel.

Leave a Reply to Jeffrey Leitheiser Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.