The reason for this is the User Account Control (UAC). Introduced with Windows Vista, User Account Control (UAC) keeps the user in a non-elevated state if not explicitly told to be elevated as an administrator.
To read more about how the User Account Control (UAC) works in Windows 10, refer to https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/how-user-account-control-works
This blog post describes how to elevate to an administrator in Powershell.
Why do you want to elevate to an administrator in Powershell?
You have opened a Powershell window, and the command that you are trying to run does not work. Of course, the issue is that you have not started an elevated window using Run as Administrator.
So, will I need to close my existing window and re-open? Re-opening a Powershell window is usually not a tedious task, but it might be if you need to input a complex password for an elevated account.
Fortunately, there is a way of solving this with a simple command from the non-elevated Powershell window.
Which Powershell actions require elevation?
There are some actions in Powershell which require you to elevate, such as:
- Changing of the Execution Policy
- Modifications to System Files
- Modifications of the Registry
I would say that it is best practice always to start an elevated Powershell window, to not run into any unexpected issues.
The only time I would not recommend this if you are testing a script with the intent of running as a regular user.
It is also possible to add a snippet in a script to check if the current session is running in elevated mode.
How to elevate and run Powershell as an administrator
Elevate Powershell to an administrator through the Windows Search
The easiest way to start an elevated Powershell windows is by searching for it.
Press the Windows button and search for Powershell. Press Run as administrator.
Create a new task in Task Manager
Press the Windows button and search for Task Manager.
Press File and Create a new task
Enter powershell and check Create this task with administrative privileges
Elevate Powershell to an administrator in an open Powershell window
Run the following command from a non-elevated Powershell prompt:
Start-Process Powershell -Verb runAs
If prompted by the UAC, enter the administrative credentials.
There are now two Powershell windows, one elevated to an administrator and one not elevated to an administrator.
I hope you have found one of the ways of opening Powershell as an administrator useful. How do you elevate to an administrator? Please leave a comment below! 🙂
- Microsoft Docs – Powershell Documentation
- Microsoft Docs – User Account Control (Windows applications)
- How To Check Bitlocker Encryption Status on Windows 10
- Add Active Directory users to groups using Powershell and a CSV file
- Add user to local administrator Group using Powershell
- How to check if Powershell is running as an administrator
- Copy a file to a new directory using Powershell
- How to create a Hyper-V Virtual Machine using Powershell
- How to change Powershell version for backward compatibility
- How to export RSOP results using Powershell