提供凭据时启动进程引发错误 - 可能的错误 [英] Start-process raises an error when providing Credentials - possible bug

查看:25
本文介绍了提供凭据时启动进程引发错误 - 可能的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您是否知道为什么在响应以下代码时会引发此错误.已验证用户名和密码正确.

Would you possibly know why this error is being raised in response to the code below. User-name and password have been verified as correct.

$secPassword = ConvertTo-SecureString "Password" -AsPlaintext -Force 
$farmCredential = New-Object System.Management.Automation.PsCredential "SharePointSP_Farm",$secPassword

Start-Process $PSHOMEpowershell.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:UsersAdministrator.SHAREPOINTAppDataLocalTempfb2956d7-87fc-4235-9f3c-742698cafe9f.ps1:8 char:14
+ Start-Process <<<<  $PSHOMEpowershell.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 $PSHOMEpowershell.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 中运行时,它确实有效.我使用以本地管理员身份运行的本地计算机帐户登录,脚本将执行定向到没有管理员权限且仅使用用户权限运行的域帐户.

NOTE: this is when executing from within PowerGUI or the ISE ide's The file fb2956d7-87fc-4235-9f3c-742698cafe9f.ps1 does exist at the path location, so for some reason the ide is having dificulty with this. Yet it DOES work when ran directly within the power shell command prompt/shell. I was logged in with a local machine account that is running as local admin, the script directs execution to a domain account which does not have admin rights and would run with just user permissions.

这是一个错误吗,因为作为开发人员,IDE 不应该被这个绊倒,因为当我在 powershell 命令提示符窗口中运行块时它可以工作??

Is this a bug, since as a developer the IDE should not be tripped up by this as it works when i run the block in the powershell command prompt window??

推荐答案

我有同样的错误.

这个功能在 Powershell ISE 上是可以的,但在 PowerGUI 上不可用

This function is OK with Powershell ISE, but doesn't work with PowerGUI

Start-Process -FilePath "C:WINDOWSSystem32cmd.exe" -Credential $credential -ArgumentList ("/c $sFileExecutable")

它与 WorkingDirectory 参数一起使用

Start-Process -FilePath 'cmd.exe' -Credential $credential -ArgumentList ("/c $sFileExecutable") -WorkingDirectory 'C:WindowsSystem32'

这篇关于提供凭据时启动进程引发错误 - 可能的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆