Start-Process -Verb Runas Output


The command Get-NetFirewallRule requires elevation and short of opening up a separate elevated pwsh session, I’m trying to use Start-Process to run the command:

Start-Process pwsh.exe -WindowStyle Maximized -Verb Runas -ArgumentList '-Command "& {Get-NetFirewallRule -DisplayName "*Event*Log*" | Select-Object DisplayName,Name,Profile,Enabled}"'

Main issue is the new pwsh window that it spawns closes once the output is shown. I’ve tried adding a Read-Host to pause the window but its just a blank window and when I hit Enter, the output is shown and the window closes immediately. Is there any way I can get the output to be shown without the window closing immediately?

Secondary issue is the new window that it spawns. The parameter -NoNewWindow does not work with -Verb. Not a biggie but is there any way to have the output in the same session window?


Just realised pwsh.exe has the -NoExit parameter … which is works well.

Would be great if I can now get the output in the same window.

A professional solution would be to use the …

… statement to prevent the script from running when it’s been started without elevation.

Another solution would be to make the script elevating itself. Search for “powershell script elevate itself” and you will find several examples how to do this.