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.?
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 ' ', '` ')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With