1

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?

Stafford Williams
  • 9,696
  • 8
  • 50
  • 101
  • My answer here should help you, its about redirecting standard output with events - http://stackoverflow.com/a/20423888/1035521 – David Martin Jan 03 '14 at 08:51

1 Answers1

3

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;