I'm trying to run a new instance of powershell.exe (from PowerShell/ISE/pwsh/VSCode) with lowered elevation using its -NoProfile
switch but haven't figured out a way to pass the -NoProfile
switch in a way that results in a newly non-elevated PowerShell console that uses the custom colors/layout that it normally would when double-clicking powershell.exe from an Explorer window.
There seem to be two fairly common approaches to lowering elevation from an elevated host/console:
- Using
runas.exe /trustlevel:0x20000 powershell.exe
- Taking advantage of explorer.exe's (default) lower trust level and doing something like this:
Start-Process $env:SystemRoot\explorer.exe $PSHome\powershell.exe
- If the user has disabled UAC, then explorer.exe will be running with elevation anyways, so this method isn't as reliable as using
runas.exe /trustlevel:0x20000 powershell.exe
- If the user has disabled UAC, then explorer.exe will be running with elevation anyways, so this method isn't as reliable as using
I've tried:
runas.exe /trustlevel:0x20000 "powershell.exe -NoProfile"
- Works, but opens a black console window.
runas.exe /trustlevel:0x20000 "explorer.exe powershell.exe -NoProfile"
- opens an Explorer window.
- Various combinations and overloads using
[System.Diagnostics.Process]::new()
and[System.Diagnostics.ProcessStartInfo]::new()
without success. - Using various forms of
start /b "" xyz
without success.
Is there another approach that would work better? Editing the registry to set the default console layout/colors isn't impossible, but it's not the most ideal or solid solution.