I am trying to write a wrapper script in Powershell which is passed the name of an executable, does some preprocessing, then invokes that executable with arguments resulting from that preprocessing. I want the executable to be anything you can run/open on Windows so I want to use Start-Process
to run it so Invoke a second script with arguments from a script (which references Invoke-Expression
) isn't really relevant. What I'm finding is that when the executable is another Powershell script, the arguments aren't seen by the script.
My stupid little test is:
Write-Output "Arg0: '$($Args[0])', Arg1: '$($Args[1])'" >>test.log
And working at a PS prompt this is what I see:
PS C:\Source> .\test.ps1 a b
PS C:\Source> more .\test.log
Arg0: 'a', Arg1: 'b'
PS C:\Source> .\test.ps1 c d
PS C:\Source> more .\test.log
Arg0: 'a', Arg1: 'b'
Arg0: 'c', Arg1: 'd'
PS C:\Source> Start-Process .\test.ps1 -ArgumentList e,f
PS C:\Source> Start-Process .\test.ps1 -Args e,f
PS C:\Source> more .\test.log
Arg0: 'a', Arg1: 'b'
Arg0: 'c', Arg1: 'd'
Arg0: '', Arg1: ''
Arg0: '', Arg1: ''
PS C:\Source>
Which is consistent with what I see when using Start-Process
in a script. I've spend a couple of hours Googling without finding an answer. Any thoughts?
I'm working on Windows 10 for development but my target is Windows Server. I don't know that that should make a difference.