Let's say I have a function that I call like this:
myfunction -msg1 'this is message 1' -msg2 'this is message2'
And here is my function:
function myfunction {
param([string]$msg1, [string]$msg2)
#HOW WOULD I Get the pre-invocation argument the function here? that is:
$preinvoke = @( "-msg1", 'this is message 1', '-msg2', 'this is message2')
write-host "You called this command like this: myfunction $preinvoke"
}
Is there a way to automatically set $preinvoke based on there real flags to the function after calling param? My impression is that param eats all the arguments... I want the list of pre-invokation arguments to the function after calling param.
$PSBoundParametersor$MyInvocation.BoundParametersshould give you what you're looking for.