PowerShell is an advanced form of command prompt. It is extended with a huge set of ready-to-use cmdlets and comes with the ability to use .NET framework/C# in various scenarios. Today, I will show you how to start a process elevated from the PowerShell prompt.
Earlier, I covered how the same can be done from a batch file. However, with Windows 10 Creators Update, Microsoft is going to de-emphasize the command prompt and promote PowerShell everywhere. See these articles for reference:
- Windows 10 build 14986 replaces Command Prompt with PowerShell everywhere
- Add Command Prompt back to Win+X Menu in Windows 10 Creators Update
- Add Command Prompt to Context Menu in Windows 10 Creators Update
- Remove Open PowerShell window here from Context Menu in Windows 10
So, it is a good idea to learn this useful trick which can be performed from the PowerShell console and save your time.
Start a Process Elevated from PowerShell
For this task, we'll use the Start-Process cmdlet. It supports a number of options, one of them is -Verb. If you specify -Verb as "RunAs", the process you are going to start will be opened elevated.
Let's try to launch the Notepad app elevated.
- Open PowerShell.
- Type or copy-paste the following command:
Start-Process "notepad.exe" -Verb RunAs
- A UAC prompt will appear. Confirm it:
- The Notepad app will be opened elevated. You can ensure this using the Task Manager. See the article: How to check if a process is running as administrator (elevated) in Windows
Tip: You can run an app elevated with the help of PowerShell directly without opening its console first. For example, you can create a shortcut or type the following command in the Run dialog:
powershell.exe -Command "Start-Process Notepad.exe -Verb RunAs"
Start a Process Elevated with Arguments from PowerShell
If you need to pass some arguments (also known as switches or parameters) to a process that you are going to start elevated from PowerShell, use the -Argument switch of the Start-Process cmdlet. Argument specified there will be passed to the target executable file. Here are modified examples with Notepad.exe I used above.
For the PowerShell console, use the following command:
Start-Process "notepad.exe" -Argument "C:\My Stuff\my file.txt" -Verb RunAs
Enclose the paths that have spaces in quotes. If you need to pass more than more argument, separate them with commas and use ArgumentList:
Start-Process "file.exe" -ArgumentList "argument1, argument2, argument3" -Verb RunAs
From within PowerShell, you can use the following command:
powershell.exe -Command "Start-Process 'Notepad.exe' -Argument 'C:\My Stuff\my file.txt' -Verb RunAs"
Yet another example:
powershell -Command "Start-Process powershell.exe -ArgumentList '-ExecutionPolicy Bypass -NoExit -Command \`"Checkpoint-Computer -Description \"RestorePoint1\" -RestorePointType \"MODIFY_SETTINGS\"\`"' -Verb RunAs"
See the article for more information: Create A Restore Point in Windows 10 with PowerShell
Enclose the paths with spaces in single quotes as shown above.
Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:
If you like this article, please share it using the buttons below. It won't take a lot from you, but it will help us grow. Thanks for your support!