0

Can ssomebody help ti run new process in the same window??

$credential = Get-Credential

Start-Process powershell.exe -Credential $credential -NoNewWindow -ArgumentList ".\ListScript.ps1" -Wait

Write-Host "Press any key to continue ..."

$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

-NoNewWindow doesn't work, but without -Credential $credential it works fine.. How can I fix that?

user1235794
  • 11
  • 1
  • 4

1 Answers1

5

Windows credentials are applied at the process level. Your first process is operating under your credentials.

If you use Start-Process without specifying other credentials, the new process can run under your existing process.

If you use Start-Process with -Credential , the new process must be launched in a process to use these new credentials. That is why you are getting a new window when using the -Credential argument.

Long story short, behavior by design. That is the way Windows handles processes and credentials. It must open a new process/window with new credentials.