0

In Powershell I am calling a custom script:

 &  C:\test.ps1 

I want to pass a custom parameter to that script. I am trying ArgumentList. But I think that only deals with predefined arguments.

 &  C:\test.ps1 -ArgumentList "Something"

I'm not sure how to pass my own custom variable to another script that I call...

  • Possible duplicate of https://stackoverflow.com/questions/27794898/powershell-pass-named-parameters-to-argumentlist/27799658?noredirect=1#comment72205135_27799658 – mjolinor Sep 18 '17 at 15:53

1 Answers1

3

You have two options in this scenario:

& C:\Test.ps1 -Switch1 -arg 'this is an arg'

Or the Start-Process cmdlet:

Start-Process -FilePath 'C:\Test.ps1' -ArgumentList @('-Switch1','-arg','this is an arg')

But this begs the question: why are you invoking a PowerShell script instead of modularizing it to a function or module to import to the script you intend to use it?

Maximilian Burszley
  • 18,243
  • 4
  • 34
  • 63