Powershell Call-Operator(&) with Parameters from Variable

Question:

G’day everyone,

I’m trying to execute a function in PowerShell with the Parameters coming from a Variable I’m not sure if it’s possible in the way I want it to but maybe someone has any idea how I would go about doing that.

Something along those lines, I don’t know in which order the Parameters get entered so I can’t use $args[n..m] or binding by position for that. Maybe there is some other Cmdlet I don’t know about that is capable of doing that?

Answer:

You can use a hastable and Splatting to do this.

Simply set each param name and value in the variable as you would a normal hastable, then pass this in using @params syntax.

The switch param however, needs a $true value for it to function correctly.

Source:

Powershell Call-Operator(&) with Parameters from Variable by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply