r/PowerShell • • Apr 05 '19

PowerShell tricks: Splatting

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

58 comments sorted by

View all comments

Show parent comments

3

u/Lee_Dailey [grin] Apr 05 '19

howdy Szeraax,

for me, it is building an array of options for robocopy & then using that as the argument list for the util. it apparently works very much like that for other arguments. something like this ...

$RC_Params = @(
    $Source
    $Destination
    $FileSpec 
    # put your current options below
    "/Log:$FullLogFileName"
    '/E'
    '/TEE'
    )

robocopy $RC_Params

it aint what i consider splatting, but it fits well enuf & is documented as such ... but i can't find the silly docs for it right now. [blush]

take care,
lee

4

u/TheIncorrigible1 Apr 05 '19

That's not splatting. You're missing the syntax.

robocopy @RC_Params

4

u/ka-splam Apr 05 '19

What difference does it make?

PS C:\> $x=@('echo','b','c')
PS C:\> cmd /c @x
b c
PS C:\> cmd /c $x
b c

4

u/TheIncorrigible1 Apr 05 '19

How it passes the arguments. $x will convert your array using ToString and doesn't pass them properly.

→ More replies (0)