when I need to schedule a PS script or to run a PS script from a command line I create a batch file containing the following two lines:
@echo off
powershell -psconsolefile "C:\Program Files\Microsoft\Exchange Server\bin\Exshell.psc1" -Command "&{%~dpn0.PS1}"
@echo off
powershell -psconsolefile "C:\Program Files\Microsoft\Exchange Server\bin\Exshell.psc1" -Command "&{%~dpn0.PS1}"
The %~dpn0.PS1 expression refers to a file with the same file name (%~n0) as the batch file, located on the same drive (%~d0) and in the folder (%~p) as the batch file.
And it correctly handles spaces in the folder name (because of double quotes).
Thus, if you need to schedule a PS script named MyScript.PS1 you need to create a CMD file named Myscript.CMD and place it into the same folder where the PS1 script resides. And that's it.
Comments
Post a Comment