I described how to set a context menu option to open a Powershell console on right click earlier.
To open Powershell as admin on right click, we can add a command to be executed on start to our registry entry like so
$stpath = pwd; Start-Process PowerShell -ArgumentList \"-NoExit\", \"-Command cd $stpath\" -verb RunAs
So our Command
in the registry entry will look like the following
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -windowstyle hidden -Command $stpath = pwd; Start-Process PowerShell -ArgumentList \"-NoExit\", \"-Command cd $stpath\" -verb RunAs
The downside of this approach is that first a normal Powershell window is opened, which opens a new Powershell window as admin if the user has the priviledges, and then the original Powershell window closes in the background.
This results in a flicker when Powershell is run as admin. 😢
If you find a flickerless approach to doing this, please leave a comment on this gist. Thanks!
I came up with a possible solution here:
"make a copy of the program, and always run this as an administrator the original doesn’t have this option."
http://variable.dk/2017/09/01/right-click-powershell-as-admin/