2

I am trying to call a script that gives data as a parameter for another script.

ex.

scriptA.ps1 -parameter1 (scriptB.ps1 -data 'testOne')

I just put () because I thought that would work but can't seem to get it to work. Any ideas? I have tried $() and "" to no avail.

Thanks.

2 Answers 2

4

In this case, you most likely have scriptb.ps1 in the same dir as scripta.ps1. PowerShell does not run scripts in the same dir without explicitly specifying the path (either absolute or relative path). The following is sufficient to make this work:

.\scripta.ps1 -parameter1 (.\scriptB.ps1 -data 'testOne')
Sign up to request clarification or add additional context in comments.

2 Comments

@Keith Hill - you are absolutely right, and I edited my answer to remove the "$" and call operator from the parameter1 argument to reflect.
No problem. PowerShell is a surprisingly deep well. I still learn new stuff about PowerShell and I've been a PowerShell MVP since 2006. :-)
2

If you want to pass scriptB.ps1 as a scriptblock, then use

./scriptA.ps1 -parameter1 {./scriptB.ps1}

If you want to pass the output of scriptB.ps1 as a type (i.e - assuming scriptB outputs a type), then use

./scriptA.ps1 -parameter1 (./scriptB.ps1)

1 Comment

Using @Keith Hill's input, I removed the call operator and the "$" from the parameter1 arguments.

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.