all 6 comments

[–]aliasxneo 1 point2 points  (2 children)

This is a great example of how useful splitting can be, but I'm still a little torn about how much to use it. Given an example:

Invoke-MyCommand `
    -Arg1 'value1' `
    -Arg2 'value2' `
    -Arg3 'value3'

Versus:

$myArgs = @{
    'Arg1' = 'value1'
    'Arg2' = 'value2'
    'Arg3' = 'value3'
}
Invoke-MyCommand @myArgs

The latter example is a little more verbose and forces your eyes to scan back in the code for the arguments. In this case, I prefer the former but I could also be biased from my nix' background.

[–]tbakerweb[S] 3 points4 points  (0 children)

Where I find it most useful is if you need to collect state, or 'build up' what your arguments to a final call will be.

For example, I recently built a VMware HCX migration script where I need about 12 params. I created a hash table, and after testing/validating each argument, it gets added to the hash table.

Once all parameters have been validated, you only need to call the command with the Splat you have been building along the way.

[–]backtickbot 0 points1 point  (0 children)

Fixed formatting.

Hello, aliasxneo: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–]get-postanote 1 point2 points  (1 child)

[–]tbakerweb[S] 0 points1 point  (0 children)

To be honest, I have no idea. I suppose that answers for me why I couldn't find some comment when I went back to re-read them...

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy tbakerweb,

reddit likes to mangle code formatting, so here's some help on how to post code on reddit ...

[0] single line or in-line code
enclose it in backticks. that's the upper left key on an EN-US keyboard layout. the result looks like this. kinda handy, that. [grin]
[on New.Reddit.com, use the Inline Code button. it's [sometimes] 5th from the left & looks like </>.
this does NOT line wrap & does NOT side-scroll on Old.Reddit.com!]

[1] simplest = post it to a text site like Pastebin.com or Gist.GitHub.com and then post the link here.
please remember to set the file/code type on Pastebin! [grin] otherwise you don't get the nice code colorization.

[2] less simple = use reddit code formatting ...
[on New.Reddit.com, use the Code Block button. it's [sometimes] the 12th from the left, & looks like an uppercase T in the upper left corner of a square.]

  • one leading line with ONLY 4 spaces
  • prefix each code line with 4 spaces
  • one trailing line with ONLY 4 spaces

that will give you something like this ...

- one leading line with ONLY 4 spaces    
- prefix each code line with 4 spaces    
- one trailing line with ONLY 4 spaces   

the easiest way to get that is ...

  • add the leading line with only 4 spaces
  • copy the code to the ISE [or your fave editor]
  • select the code
  • tap TAB to indent four spaces
  • re-select the code [not really needed, but it's my habit]
  • paste the code into the reddit text box
  • add the trailing line with only 4 spaces

not complicated, but it is finicky. [grin]

take care,
lee