Using raw with path with whitespace in it

raw: 'powershell.exe -Nologo -file C:\Program Files\App\install-service.ps1'
"module_name": "raw"}, "rc": 1, "stderr": "Processing -File 'C:\Program' failed because the file does not have a '.ps1' extension. Specify a valid Windows PowerShell script file name, and then try again.\r\n", "stdout": "", "stdout_lines": []}

How does one escape the \ and the whitespace in a path used in the raw module?

In a playbook, assuming you are using ansible 2.x then you should be able to leave out the single quotes for a hard coded path like this

raw: powershell.exe -NoLogo -file C:\Program Files\App\install-service.ps1

If you need to use a variable then use double quotes and double backslashes

raw “powershell.exe -NoLog -file C:\Program Files\App\install-service.ps1”

Be aware there’s a bug right now if you are passing in windows paths as -e or with key=value to the ansible command so \a looks like a unicode escape sequence. You can usually work around it by using an upper case path \A

By the way, the raw module is running powershell, so you might not need to start with powershell.exe

Also, if you are installing a windows service (or wrapping up an executable so that it can be controlled as a windows service), you might be able to use the win_nssm module (if you don’t mind installing nssm).