2

I wrote a PowerShell script that's accepting input from the pipeline plus some parameters.

Now, when I want to call the script from another directory, the following doesn't work:

Get-ChildItem | 'D:\My Documents\PowerShell\My-Script.ps1' -MyParam 1 -OtherParam 'Test'

How do I call a PowerShell script residing at a path having spaces from another directory with parameters and pipeline input?

3
  • 2
    Use the call operator | & 'D:\My Documents\PowerShell\.... Commented Mar 13, 2023 at 20:50
  • 1
    In short: An executable path that is quoted or contains variable references must - for syntactic reasons - be invoked with &, the call operator; see the linked duplicate for details. Commented Mar 13, 2023 at 21:23
  • Solution and reasoning of the other issue might be the same, but the question is completely different. I'm pretty sure that no-one searching for a question like mine will ever find the other answer. Please reopen. Commented Mar 14, 2023 at 23:18

1 Answer 1

2

This may help you:

Get-ChildItem | & "D:\My Documents\PowerShell\My-Script.ps1" -MyParam 1 - 
OtherParam 'Test'
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.