提供凭据时启动进程引发错误

编程入门 行业动态 更新时间:2024-10-28 00:18:08
本文介绍了提供凭据时启动进程引发错误 - 可能的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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'

更多推荐

提供凭据时启动进程引发错误

本文发布于:2023-10-24 09:18:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523554.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:凭据   进程   错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!