1
votes

So I am trying to run a powershell script on windows server from a .bat file and I keep getting this error.

This is the only line I have in my script: start /d "C:\Windows\SysWOW64\WindowsPowerShell\v1.0\" Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\path\to\scripts\awesomescript.ps1'"

I have successfully run that command by itself in the cmd window by copying/pasting that whole line into the cmd prompt. The script has been tested as well.

However the same command will not work in the batch file and gives me the error "The syntax of the command is incorrect".

Does anyone happen to know why?

Update:

Thank you to the poster. I merely exited my old command prompt and started a new one. That old command and the previous posters worked. I hate those little things with windows.

Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\path\to\script\script.ps1'"

I will be keeping the posters answer as the accepted.

Thank you!

1

1 Answers

0
votes

Why are you putting path before powershell.exe? Seems to be working without this full path:

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\Users\SE\Desktop\ps.ps1'"

Look there.