Use splatting to pass parameters and arguments

A simple but useful trick. Instead of specifying parameters and arguments to a cmdlet on the same line as the cmdlet, you can put these into a hash-table and “splat” the table to the cmdlet. Here’s an example.

Old way:

New way:

Notice you pass the variable $colors with a @ sign instead of the usual $ sign. That’s what splats the variable. The hash-table is broken and the keys treated as parameter names and values treated as arguments.

You can use this trick with any cmdlet.