我有一个查询,例如当我尝试执行包含带空格的路径的表达式时,出现如下错误。
代码:
$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
你能帮我解决这个问题吗?
使用单引号和反引号(重音符号)来转义空格:
$path='E:\Test\My` space\Log'
Invoke-Expression $path
或者编程:
$path="E:\Test\My space\Log"
Invoke-Expression ($path -Replace ' ', '` ')
| 归档时间: | 
 | 
| 查看次数: | 5668 次 | 
| 最近记录: |