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
Note: If you press the "No" button at the UAC prompt, the PowerShell console will print out an error message "The operation was canceled by the user.". This is expected.
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"
The result will be the same. The Powershell window will flash for a moment and then the app will be opened elevated.
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.
That's it.
Support us
Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:
Microsoft wants to impress everyone with the “Verb-Noun” syntax of PowerShell – “It is all standard, no command will ever have totally different parameters like on Unix, bla bla.” And then there is this: -Verb RunAs. Makes absolutely no sense. It’s not -RunElevated, it’s not -RunAsAdmin, or something that would make sense, nope, it’s -Verb RunAs…
Hi,
I’m trying to do the same to run a powershell script in elevated mode, but from a Jenkins console. when using the below in cmd it runs in admin mode but asks for prompt. How do I do the same without prompting.(Jenkins runs as service with admin user already)
powershell.exe -command “start-process powershell.exe -Argumentlist ‘-executionpolicy bypass -noexit -file “\view_kill_process.ps1″‘ -verb RunAs”
Please suggest me on this. thanks in advance