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

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

问题描述

您是否可能知道为什么响应下面的代码而引发此错误.用户名和密码已验证为正确.

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 "SharePoint\SP_Farm",$secPassword

Start-Process $PSHOME\powershell.exe -Credential $FarmCredential -ArgumentList "-NoExit","-Command `"&{`$outvar1 = 4+4; `"write-output `"Hello:`"`$outvar1`"}`"" -Wait

错误;

the error;

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中运行时,它确实起作用. 我使用一个以本地管理员身份运行的本地计算机帐户登录,该脚本将执行定向到一个没有管理员权限且仅具有用户权限的域帐户.

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.

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

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:\WINDOWS\System32\cmd.exe" -Credential $credential -ArgumentList ("/c $sFileExecutable")

它与WorkingDirectory参数一起使用

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

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

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