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?

AxD
  • 2,714
  • 3
  • 31
  • 53
  • 2
    Use the call operator `| & 'D:\My Documents\PowerShell\....` – Santiago Squarzon Mar 13 '23 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](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Operators#call-operator-); see the linked duplicate for details. – mklement0 Mar 13 '23 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. – AxD Mar 14 '23 at 23:18

1 Answers1

2

This may help you:

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