Run PowerShell script as Administrator
Jump to navigation
Jump to search
Contents
About
By default on Windows, there is no easy way to run a PowerShell script as administrator.
You cannot elevate from the script with 'Run with PowerShell', so you have to run PowerShell from Start as administrator, browse to the directory of the script, and open/run it every time.
This small add-on will give you the ability to "Run as Administrator" any PowerShell .ps1 script file, from the right-click menu.
Install
Manual
- Open Registry Editor (regedit.exe).
- Browse to: HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell
- Create a new Key called: RunAs
- In this Key, create a new Key called: Command
- In this Key, edit the (Default) Key
- Enter the same value as the (Default) value in "0\Command", in this case:
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'"
Automatic
This file will also add icons to all the PowerShell menu options.
Download .reg-file: File:PowerShell Run As Administrator.reg
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\0] "Icon"="%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe" [HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\Edit] "Icon"="%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell_ise.exe" [HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\RunAs] "HasLUAShield"="" [HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\RunAs\Command] @="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" \"-Command\" \"if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'\""