您可能知道为什么响应下面的代码会引发此错误。用户名和密码已被验证为正确。
$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 对此有困难。然而,当直接在 power shell 命令提示符/shell 中运行时,它确实有效。我使用以本地管理员身份运行的本地计算机帐户登录,该脚本将执行定向到没有管理员权限且仅使用用户权限运行的域帐户。
这是一个错误吗,因为作为开发人员,IDE 不应该被它绊倒,因为当我在 powershell 命令提示符窗口中运行该块时它可以工作?