How to Run PowerShell Script as Administrator (Elevate)


In order to Run PowerShell Script as a run Administrator on your Windows (10/11) or Windows Server, you can follow the below easy steps to elevate to an Admin.


Option 1: Right-Click on PowerShell Script file -> Run As Administrator

    This is the quickest way to execute the script as an Administrator is by right-clicking on it and choosing "Run as Administrator".


Option 2: Using Start Menu

    Windows Start - PowerShell - Run as Administrator
    1. Press Windows Button to open Search.
    2. Now Type PowerShell.
    3. On the PowerShell icon, right-click and select "Run as Administrator
    4. Navigate to your PowerShell script and execute it.

Option 3: Using Command Prompt

    1. Press Windows Button to open Search.
    2. Now Type Command Prompt.
    3. On the Command Prompt icon, right-click and select "Run as Administrator" to elevate to admin to run Powershell Script.
    4. You can execute the script as below,
      powershell -ExecutionPolicy Bypass -File "D:\script.ps1

Option 4: using start-process cmdlet to elevate to Admin

    If you have already logged into PowerShell and want to elevate as an Administrator, then you can make use of the start-process cmdlet.

    start-process PowerShell verb runas
    PowerShell RunAs elevated administrator command

    You can also run your script in admin mode with the below one-liner.

    Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -File D:/scripts/schedular_task.ps1" -Verb RunAs
-

Facing issues? Have Questions? Post them here! I am happy to answer!


Author: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap