r/PowerShell • • Apr 05 '19

PowerShell tricks: Splatting

https://blog.destruktive.one/powershell-tricks-splatting/
150 Upvotes

58 comments sorted by

View all comments

27

u/si1ic0n_gh0st Apr 05 '19

Splatting doesn't sound all that cool, until you realize that you can use it to vary what arguments you pass to a cmdlet/program. To build on Destruktive's example, there might be times where you don't want to set OpenPorts or maybe sometimes you'll need to also add PublicIpAddressName.

With splatting you can dynamically build your arguments, then hand them off to whatever you are trying to execute. Really cleans up your code.

2

u/[deleted] Apr 06 '19

I don’t think the example in the link showed how that conditional parameter setting would be done, could you post a basic example?

2

u/destruktive Apr 06 '19

Will absolutely do an example of this later on, there will be a follow up :)

1

u/[deleted] Apr 06 '19

Thanks, it’s much appreciated!