PowerShell ISE supports two kinds of user privileges:
Standard privileges: These kinds of privileges can do specific tasks only. For instance, you cannot use all the system’s functionalities specifically that require “Run as Administrator” because of security. To overcome this, it is recommended to use PowerShell with admin privileges.
Administrator Privileges: This privilege allows you to do all the tasks, including the standard privileges tasks.
In this article, we will illustrate various ways to run the PowerShell script with administrator privileges:
Method 1
A primary way to open your PowerShell ISE:
Click on the “Search” icon available on the taskbar. After opening it, type “PowerShell ISE” to search. Right-click on the “PowerShell ISE”, and click “Run as Administrator“:
Once it is opened, you can write a script, save it, and execute it using administrator privileges:
Method 2
In this method, we will use Windows built “Run” dialogue to run the script as an administrator:
Press “Windows key + R” to open the “Run” dialogue. Once the dialogue box is opened, type “PowerShell ISE” and hit OK.
It is observed that the script is opened with standard privileges:
Method 3
We can also redirect the standard script to administrator script using PowerShell cmdlet “Start-Process” and a flag “-Verb“. Copy and paste the following command to redirect to administrator privileges:
The time you execute the command, another PowerShell ISE console will open with admin privileges.
Method 4
This method is used to open the PowerShell using Windows Task Manager. First, press “ctrl+shift+esc” from your keyboard to open Task Manager.
Once it is opened, navigate to the “File” option available on the menu bar of the task manager.
Click on File, and you will get two options. You have to click on “Run new task“:
By clicking “Run new task“, a “Run” dialogue box will be opened:
Type “PowerShell ISE” in the search field of the “Run“. To run it as administrator privileges, check the option given below the search field and click on “OK” to run the task:
Method 5
You can use a built-in Windows Task Scheduler to execute PowerShell ISE as an administrator. First, you have to open Task Scheduler. Click on the Search icon in the taskbar and type “Task Scheduler“:
Once it is opened, you can observe a “Create Task” option under the “Actions” tab. Click on the “Create Task” option:
It will open up a new window. Here, you have to enter a few information such as “Name” of the task. You can set any name to the task. You must select the option “Run with highest privileges” to run the task as an admin. Then, choose your operating system from the dropdown menu “Configure for“:
After customizing this tab, click on the “Actions” tab given on the menu bar. Click on “New” to add an action to the task:
You have to give the .exe path of the “PowerShell ISE” file, which can be found here:
64bit Operating System C:\Windows\System32\WindowsPowerShell\v1.0\powershell_ise.exe
Or:
Give the path of the ISE file and click “OK“:
Click on “OK” to complete the creation of the task. The new task is added to “Task Scheduler Library” in the “Task Scheduler“. To run the task, click on the “Task Scheduler Library“, and you will find a task “PowerShell ISE“. Click on the task and run the task. The PowerShell ISE will start with admin privileges:
Apart from these methods, few checks can be performed on PowerShell ISE.
How to Check the Privilege of PowerShell ISE
Suppose you are using PowerShell or PowerShell ISE. In that case, you can perform a security check to confirm that the current session is using administrator privileges or not. Copy and paste the following command in the PowerShell Terminal:
Note: there are two possibilities:
False: If the current session of the PowerShell ISE is not using administrator privileges, then it would return “False“.
True: If the command’s output returns “True“, then it means you are running the script with administrator privileges.
How to Restrict the Script to Run as Administrator
In case you forgot to run the script as an administrator, the PowerShell script has a check option. It will check the privileges of the script. If the script is running with the Administrator, it will enable the execution of the script. However, if the script is not using administrative privileges, it will not allow the execution. Copy and paste the following command in PowerShell ISE scripts to check:
We have created a simple script that prints an integer value and saves the script as “check.ps1“. If the script is not using administrator privileges, then it will display the error message as shown in the image below:
We will try to run the same script (check.ps1), with the exact requirement. However, we have opened the PowerShell with administrator privileges. In this case, it will not stop the execution of the script, as shown below:
Conclusion:
In a secure computing environment, the privileges of users are assigned carefully and strictly monitored. All these restrictions are linked to the privacy and security of the respective organization or company. Therefore, to attain better privacy, user privileges should be assigned accordingly.
In this post, we have demonstrated the different methods to open the PowerShell scripts with administrator privileges. This guide will enable you to restrict the PowerShell scripts to run only with admin privileges. Moreover, you can also check the privilege of the current PowerShell session.