[英]Powershell start-process : combinaison Credential/WorkingDirectory fail
I'm using powershell to start process as another user.我正在使用 powershell 作为另一个用户启动进程。 To do this I'm using "Start-Process" as below.为此,我使用如下所示的“Start-Process”。
$creds = Get-Credential -UserName $Name -Message "Please enter authorized credentials"
Start-Process `
-Credential $creds `
"C:\MyPowerfullProcess.exe" `
-RedirectStandardOutput $logOutputPath `
-RedirectStandardError $logErrorPath `
-WorkingDirectory $workingPath `
-ArgumentList $processArg
Stop-Transcript
The problem is that the $workingPath is only accessible to the user $creds and not by the user who started the.ps1 script.问题是 $workingPath 只能由用户 $creds 访问,而不能由启动 .ps1 脚本的用户访问。 And The Start-Process command trough this error: "WorkingDirectory" Invalid [..] DirectoryNotFoundException Start-Process 命令通过此错误:“WorkingDirectory”无效 [..] DirectoryNotFoundException
Start-Process启动进程
- CategoryInfo: InvalidOperation: (:) [Start-Process], DirectoryNotFoundException CategoryInfo: InvalidOperation: (:) [启动进程], DirectoryNotFoundException
- FullyQualifiedErrorId: DirectoryNotFoundException,Microsoft.PowerShell.Commands.StartProcessCommand FullyQualifiedErrorId:DirectoryNotFoundException,Microsoft.PowerShell.Commands.StartProcessCommand
Try to use the following -Verb
addition to specify the run-as.尝试使用以下-Verb
添加来指定运行方式。
$creds = Get-Credential -UserName $Name -Message "Please enter authorized credentials"
Start-Process `
-Credential $creds `
"C:\MyPowerfullProcess.exe" `
-RedirectStandardOutput $logOutputPath `
-RedirectStandardError $logErrorPath `
-WorkingDirectory $workingPath `
-ArgumentList $processArg `
-Verb RunAsUser
Stop-Transcript
Source: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process来源: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.