Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell-从带有空格的路径运行命令_Powershell - Fatal编程技术网

Powershell-从带有空格的路径运行命令

Powershell-从带有空格的路径运行命令,powershell,Powershell,我试图从存储在变量中的路径执行一个进程,该变量的值是Get Location命令的结果。 这仅在目录没有空格时有效。 我找到了许多方法来美化空间,但这些方法只有在手动指定路径时才起作用。 还有别的办法吗 代码如下: $userCred = Get-Credential "Domain\$admAccount" $currentDir = Get-Location Start-Process "pwd_user.exe" -WorkingDirectory $currentDir -Credent

我试图从存储在变量中的路径执行一个进程,该变量的值是Get Location命令的结果。 这仅在目录没有空格时有效。 我找到了许多方法来美化空间,但这些方法只有在手动指定路径时才起作用。 还有别的办法吗

代码如下:

$userCred = Get-Credential "Domain\$admAccount"
$currentDir = Get-Location
Start-Process "pwd_user.exe" -WorkingDirectory $currentDir -Credential $userCred
我试过:

"$currentDir"
$currentDir -replace ' ', '` '
&$currentDir
"&$currentDir"

这些都不起作用。

WorkingDirectory的默认值是当前目录。我不明白为什么首先需要这个变量。至于变量,我想你可以尝试一下扩展路径属性

Start-Process "pwd_user.exe" -WorkingDirectory $currentDir.Path -Credential $userCred
对于不成功的替换,您需要扩展属性

$currentDir.Path -replace ' ', '` '

你说没有这些工作是什么意思?它是如何失败的?在我的系统上运行良好,不过可能不需要使用Get Location。您可以尝试启动进程pwd_user.exe-WorkingDirectory-凭证$userCred-使用。以引用您所在的目录。