How to run a powershell script with white spaces in path from command line?

Home / powershell / How to run a powershell script with white spaces in path from command line?

Question:
So I’ve tried a bunch of different ways to run a powershell script from the command line and every single one returns an error.

Here is this path:
C:UserstestDocumentstestline spacePS Scripttest.ps1
I’ve tried these:powershell -File ‘"C:UserstestDocumentstestline spacePS Scripttest.ps1"’

powershell "& ""C:UserstestDocumentstestline spacePS Scripttest.ps1"""

Powershell "& ‘C:UserstestDocumentstestline spacePS Scripttest.ps1’"

Powershell -File ‘C:UserstestDocumentstestline spacePS Scripttest.ps1’"
I get all these errors:

& : The term ‘C:UserstestDocumentstestline spacePS Script’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Processing -File ”C:UserstestDocumentstestline spacePS Script” failed: The given path’s format is not support ed. Specify a valid path for the -File parameter.

Any help would be greatly appreciated!


Answer:
In your examples, you’re mixing quotes and double quoting for no reason.
IF EXIST "C:UserstestDocumentstestline spacePS Scripttest.ps1" (
powershell -ExecutionPolicy Unrestricted -File "C:UserstestDocumentstestline spacePS Scripttest.ps1"
)
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *