Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Powershell, Invoke-expression is not working when entering space in the path

I have a query like when I try to execute the expression which contains a path with space, I am getting an error as below.

Code:

$path="E:\Test\My space\Log"
Invoke-Expression $path 

E:\Test\My: The term 'E:\test\My' 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.
At line:1 char:1
+ E:\Test\My space\Log
+ ~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (E:\Test\My :String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Could you please help me to fix this issue.?

like image 748
Bharathi Avatar asked Oct 17 '22 08:10

Bharathi


1 Answers

Use single quotes and a backtick (grave accent) to escape the space:

$path='E:\Test\My` space\Log'
Invoke-Expression $path

Or programmed:

$path="E:\Test\My space\Log"
Invoke-Expression ($path -Replace ' ', '` ')
like image 109
iRon Avatar answered Oct 21 '22 02:10

iRon