3

I thought this would be simple to do, but I am stuck.

Script1.ps1 contains:

$params = "abc", "def"
Script2 $params

Script2.ps1 contains:

Args.Count

This of course will output "1" for the single array argument that Script2 receives.

I want to find a way to pass $params not as a single array, but as two separate arguments -- so that Script2 outputs "2" for the count and args[0] is "abc" and args[1] is "def".

I tried all different ways to do this, but I never ended up with what I wanted.

1 Answer 1

7

Like this:

$params = "abc", "def"
Script2 @params
Sign up to request clarification or add additional context in comments.

2 Comments

This technique is called "splatting."
Thanks. One thing that was confusing me was something that I just noticed about $args. If include the expression, $args.Count, in the script, it prints the correct value. But if I put a breakpoint on this expression and type $args.Count in the command window, it always displays "0".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.