I am attempting to call a Powershell script in cmd.exe and the script is in a location that looks like this: c:Data\foo - bar\location-1\ShellScript.ps1
When I am calling this script I have tried using single and double quotes around the path with no luck.
PowerShell.exe -File "c:\Data\foo - bar\location-1\ShellScript.ps1" Arg1 Arg2
From what I have read I assumed that the above would work but this did not work nor did single quotes.
I appreciate any ideas.
Thanks *Edit * Mistype on my example path. Sorry.
One solution is to move to PowerShell v3 where this works fine:
PS> powershell.exe -file 'C:\temp\foo - bar\location-1\foo.ps1' arg1 arg2
made it!, args are arg1, arg2
If you need to stay on V2 try escaping the spaces e.g.:
PS> powershell.exe -file "C:\temp\foo` -` bar\location-1\foo.ps1" arg1 arg2
From cmd.exe, this should work:
C:\> PowerShell.exe -Command "& {& 'c:\Data\foo - bar\location-1\ShellScript.ps1' Arg1 Arg2}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With