Hi Pablo,
you probably need to double the backslashes. Something like
powershell -command "&D:\\Path\\Script.ps1"
You might need to experiment somewhat though.
Let me give you a little background:
In a Unix/Linux environment there is a system call execv() which is used to load a new program and to execute it.
The basic method to spawn a new process ist to fork() first, which will create a copy of the calling process, and then to execv() the desired program.
The execv() call (it's actually an entire family of system calls) allows to specify the command line as an array of arguments.
This array remains untouched by the OS and corresponds to the argv[] array in your program.
The scheduling server parses the defined run program (according to Bourne shell rules,, replaces the parameters with their values, and creates such an argv array which is then used to create the new process.
In a Windows environment there is a CreateProcess() system call.
This system call expects a command line to execute, not an array of arguments (where argv[0] is the name of the program to execute).
Hence the job server has no other choice than to concatenate the argv array in order to create a command line that is then parsed by the Windows system.
Internally Windows creates such an argv array again (explicitly or implicitly, no idea). But this procedure easily breaks any serious quoting attempts.
It is important to note that we try to construct a Windows command line, based on the argv array, in a way that the single command line parameters are preserved.
We do this by enclosing the entries in double quotes.
Hence and array like
argv[0] = powershell
argv[1] = -command
argv[2] = & 'D: \ Path \ Script.ps1'
will be converted to
powershell "-command" "& 'D: \ Path \ Script.ps1'"
which, due to the single quoting and the spaces, probably won't work.
In contrast, my suggestion, parsed by the scheduling server, yields
argv[0] = powershell
argv[1] = -command
argv[2] = &D:\Path\Script.ps1
which then is converted to
powershell "-command" "&D:\Path\Script.ps1"
which has a positive probability of being correct.
Windows users aren't out of trouble yet.
There is a difference between the treatment of bat files and exe files.
If you run a bat file that simply prints its command line arguments, you'll find that Windows preserves the quoting, while this is not true for exe files.
Hence a call like
echo.bat "hello world"
will print
"hello world"
A call like
echo.exe "hello world"
will print
hello world
(Side note: I didn't test this behaviour for quite some time now. Things might have changed in the meanwhile).
I hope this explanation sheds some light into the dark.
Best regards,
Ronald