PowerShell is an object-oriented command-line automated tool mainly used by system administrators and IT experts to automate various tasks related to operating systems. PowerShell has its extended version known as PowerShell ISE. It allows you to create scripts and run them. The PowerShell ISE console consists of two parts: a scripting pane and an output pane. Scripts are written in the scripting pane, and the script’s output can be seen in the output pane.

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“:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-539.png" data-lazy- height="670" src="data:image/svg xml,” width=”675″>

Once it is opened, you can write a script, save it, and execute it using administrator privileges:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-540.png" data-lazy- height="354" src="data:image/svg xml,” width=”897″>

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:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-541.png" data-lazy- height="297" src="data:image/svg xml,” width=”902″>

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:

> StartProcess PowerShell ISE -Verb runAs

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-542.png" data-lazy- height="278" src="data:image/svg xml,” width=”715″>

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“:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-543.png" data-lazy- height="264" src="data:image/svg xml,” width=”1035″>

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:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-544.png" data-lazy- height="304" src="data:image/svg xml,” width=”706″>

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“:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-545.png" data-lazy- height="670" src="data:image/svg xml,” width=”643″>

Once it is opened, you can observe a “Create Task” option under the “Actions” tab. Click on the “Create Task” option:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-546.png" data-lazy- height="564" src="data:image/svg xml,” width=”786″>

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“:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-547.png" data-lazy- height="507" src="data:image/svg xml,” width=”640″>

After customizing this tab, click on the “Actions” tab given on the menu bar. Click on “New” to add an action to the task:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-548.png" data-lazy- height="452" src="data:image/svg xml,” width=”592″>

You have to give the .exe path of the “PowerShell ISE” file, which can be found here:

32bit Operating System C:WindowsSystem32WindowsPowerShellv1.0powershell_ise.exe

64bit Operating System C:WindowsSystem32WindowsPowerShellv1.0powershell_ise.exe

Or:

C:WindowsSysWOW64WindowsPowerShellv1.0powershell_ise.exe

Give the path of the ISE file and click “OK“:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-549.png" data-lazy- height="483" src="data:image/svg xml,” width=”585″>

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:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-550.png" data-lazy- height="567" src="data:image/svg xml,” width=”787″>

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:

> [Security.Principal.WindowsIdentity]::GetCurrent().Groups -contains ‘S-1-5-32-544’

Note: there are two possibilities:

False: If the current session of the PowerShell ISE is not using administrator privileges, then it would return “False“.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-551.png" data-lazy- height="173" src="data:image/svg xml,” width=”788″>

True: If the command’s output returns “True“, then it means you are running the script with administrator privileges.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-552.png" data-lazy- height="182" src="data:image/svg xml,” width=”838″>

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:

> #Requires -RunAsAdministrator

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:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-553.png" data-lazy- height="274" src="data:image/svg xml,” width=”962″>

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:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-554.png" data-lazy- height="220" src="data:image/svg xml,” width=”397″>

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.