The following opens in a new window, I guess because the new window represents the process running under a different credential:
Start-Process ipconfig -Credential domain\user -NoNewWindow
The documentation here doesn't seem to point this out.
Considering this is occuring, and I need to run with with elevated privilages, how can I get the output of the above command back into my console?
Use the -RedirectStandardOutput
parameter to redirect the output to a file. Then, read the file contents back into your PowerShell sessions.
# 1. Get an alternate credential
$Cred = Get-Credential;
# 2. Start the process, redirecting the output to a file
Start-Process -Credential $Cred -FilePath ipconfig.exe -NoNewWindow -Wait -RedirectStandardOutput $env:windir\temp\ipconfig.log;
# 3. Retrieve the content from the log file
Get-Content -Path $env:windir\temp\ipconfig.log;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.