- This topic has 6 replies, 4 voices, and was last updated 2 months, 3 weeks ago by
November 25, 2019 at 4:06 pm #190357
The following code works. But I don’t get any error codes from the called process
Start-Process powershell.exe -Verb runas -ArgumentList "$Command" -Wait -PassThru
The following code returns the error messages from the called process. Powershell does not seem to be running elevated rights despite $oProcessInfo.Verb = “RunAs”.
$oProcessInfo = New-Object System.Diagnostics.ProcessStartInfo $oProcessInfo.FileName = $sProcess $oProcessInfo.Verb = "RunAs" $oProcessInfo.RedirectStandardError = $true $oProcessInfo.RedirectStandardOutput = $true $oProcessInfo.UseShellExecute = $false $oProcessInfo.Arguments = $sArgs $oProcessInfo.CreateNoWindow = $true $oProcess = New-Object System.Diagnostics.Process $oProcess.StartInfo = $oProcessInfo $oProcess.Start() | Out-Null $oProcess.WaitForExit() | Out-Null $sSTDOUT = $oProcess.StandardOutput.ReadToEnd() $sSTDERR = $oProcess.StandardError.ReadToEnd() $pOutPut.Value="Commandline: $sProcess $sArgs`r`n" $pOutPut.Value+="STDOUT: " + $sSTDOUT + "`r`n" $pOutPut.Value+="STDERR: " + $sSTDERR + "`r`n"
Does anyone have an idea what I’m doing wrong or how can I solve my problem?
November 25, 2019 at 4:17 pm #190360Senior ModeratorTopics: 8Replies: 1158Points: 4,045Rank: Community Hero
you can use -RedirectStandardError parameter with Start-Process, it accepts a file name where it will write the error. Similarly for -RedirectStandardOutput
November 25, 2019 at 4:27 pm #190363
Can I spend that directly or do I have to go through a file export?
November 25, 2019 at 5:27 pm #190378
November 26, 2019 at 7:27 am #190474
In the help I find the following:
- Specifies a file.
- By default, the errors are displayed in the console.
If I do not specify a parameter after -RedirectStandardOutput I get a error message, Enter a parameter of type “System.String”.
If I pass a variable behind it, it will not be filled. So where is the mistake? Or, how is the Help to understand?
November 26, 2019 at 7:48 am #190483
The combination -Verb runas and -RedirectStandardOutput C: \temp\Error.txt also results in error:
The parameter set can not be resolved with the given named parameters
start-Process powershell.exe -Verb runas -ArgumentList "$Command" -Wait -PassThru -RedirectStandardOutput C:\temp\Error.txt
November 26, 2019 at 4:55 pm #190552ParticipantTopics: 6Replies: 19Points: 77Rank: Member
- You must be logged in to reply to this topic.