Notice: curl_setopt() [function.curl-setopt]: CURLOPT_SSL_VERIFYHOST no longer accepts the value 1, value 2 will be used instead in /www/blog/wp-includes/class-http.php on line 1348
How to call a Powershell script with a path having white space from command line | CionSystems Blog

How to call a Powershell script with a path having white space from command line

January 27, 2021
By shareef

How to call a script from PowerShell console when the script file path contains white space.

PS C:\> c:\new folder\myscript.ps1 param1 (will give the below error)

The term ‘c:\new’ is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again.

Putting the path in between the quotations like this:

PS C:\> “c:\new folder\myscript.ps1″ param1

Will lead to: Unexpected token ‘param1′ in expression or statement.

And the solution is to use the Invoke Operator “&”, which is used to run script blocks

PS C:\> & ‘c:\new folder\myscript.ps1′ param1

Now coming to the next step.

Executing a PowerShell script from command line.

C:\Documents and Settings\Simon>powershell c:\MyScript.ps1 param1

C:\Documents and Settings\Simon>powershell c:\new folder\MyScript.ps1 param1

Again it gives the below error.

The term ‘c:\new’ is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again.

With the help of PowerShell below is the solution.

C:\Documents and Settings\Simon>powershell -command “& {&’c:\new folder\MyScript.ps1′ param1}”

Leave a Reply