(Solved) PowerShell the Requested Operation Requires Elevation

See here how to fix the "requested operation requires elevation" in PowerShell, and also how to fix it if you are running a PowerShell script.

If you see the error “the requested operation requires elevation” when running a command in Windows PowerShell, it simply means that you need to run PowerShell as administrator.

To run PowerShell as administrator, open PowerShell and then run the following start-process command to open a PowerShell console with elevated privileges:

Start-Process powershell -Verb runAs

After running the command, click yes to allow Windows to make changes to your device.

If you want to run a Powershell script as an administrator, keep reading.


How to Fix Powershell Script the Requested Operation Requires Elevation

If you want to self-elevate your PowerShell script, you only need to add a snippet at the beginning of your script.


How to Elevate PowerShell with a Self-Elevating Snippet

To elevate your PowerShell script, add the following snippet in the beginning of your script.

if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] “Administrator”)) {

    Start-Process powershell.exe “-NoProfile -ExecutionPolicy Bypass -File `”$PSCommandPath`” `”$args`”” -Verb RunAs;

    exit;

}

Please note that this snippet does not keep the working directory:


How to Elevate PowerShell while Keeping the Current Working Directory

If your script performs path-relative operations, it is important that you run a self-elevating snippet PowerShell for PowerShell that preserves the working directory.

The snippet below does that:

if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {

    Start-Process PowerShell -Verb RunAs “-NoProfile -ExecutionPolicy Bypass -Command `”cd ‘$pwd’; & ‘$PSCommandPath’;`””;

    exit;

}


Conclusion

The error “the requested operation requires elevation” appears whenever you run a PowerShell command that requires administrator privileges. These are commands that can change your system in some way.

To simple solution to this error is to run the following command on PowerShell:

Start-Process powershell -Verb runAs

But if you want to self-elevate your PowerShell script to run with administrator privileges, check the section just above this conclusion to learn how to do it with and without preserving the working directory.

If you need to troubleshoot your PC, I wrote an article on how to disable restart on automatic system failure and why you should do it.

Laerthe Côrtes

Laerthe Côrtes

My first desktop computer, back in the 1990s, opened a whole new world for me; since then I am a heavy PC user (who will never get used to smartphones.) I worked for five years in the PC software industry, and my favorite version of Windows is still Windows 95.

About Us

No matter who you are, if a seasoned computer user or someone who can’t do much more than browse the internet, my mission is the same – to help you find a solution to the problem plaguing your PC, or, at the very least, to give you a direction of what to do next.

Legal Information

Some of our posts contain affiliate links to help keep this website running. This means I recommend products and services I personally use and I may receive a commission if you purchase them.

Must-Have Software List

You might also like