您是否知道为什么会出现以下代码的响应中引发此错误?用户名和密码已被验证为正确。
$secPassword = ConvertTo-SecureString "Password" -AsPlaintext -Force
$farmCredential = New-Object System.Management.Automation.PsCredential "SharePoint\SP_Farm",$secPassword
Start-Process $PSHOME\powershell.exe -Credential $FarmCredential -ArgumentList "-NoExit","-Command `"&{`$outvar1 = 4+4; `"write-output `"Hello:`"`$outvar1`"}`"" -Wait
错误;
Start-Process : This command cannot be executed due to the error: The directory name is invalid.
At C:\Users\Administrator.SHAREPOINT\AppData\Local\Temp\fb2956d7-87fc-4235-9f3c-742698cafe9f.ps1:8 char:14
+ Start-Process <<<< $PSHOME\powershell.exe -Credential $FarmCredential -ArgumentList "-NoExit","-Command `"&{`$outvar1 = 4+4; `"write-output
`"Hello:`"`$outvar1`"}`"" -Wait
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
然而,这很好地运作。
Start-Process $PSHOME\powershell.exe -ArgumentList "-NoExit","-Command `"&{`$outvar1 = 4+4; `"write-output `"Hello:`"`$outvar1`"}`"" -Wait
注意:这是在PowerGUI或ISE IDE中执行时发生的情况。 文件fb2956d7-87fc-4235-9f3c-742698cafe9f.ps1确实存在于路径位置,因此IDE出现了一些困难。但是,当直接在PowerShell命令提示符/ shell中运行时它确实可以工作。 我使用本地机器帐户登录,该帐户作为本地管理员运行,脚本将执行方向指向一个没有管理员权限的域帐户,并将以普通用户权限运行。
作为开发人员,IDE不应该被这种情况绊倒,所以这是一个bug吗?因为当我在PowerShell命令提示符窗口运行块时它可以正常工作。