How to Run the PowerShell Script in Scheduled Task with Run as Administrator

By | August 30, 2018

run powershell script as administrator: PowerShell Script not working through Task Scheduler: how to execute powershell script to run as administrator in a scheduled task? some PowerShell scripts are failed to run on scheduled task and it won’t through any error on task history (even on the task scheduler events didn’t get any errors) just didn’t get the output what we expect (this is happening on Windows server 2012 R2 and 2016), however the same script able to run without any issue directly, done extensive debugging on the PowerShell script and found error related to ActiveX, how to fix this

Also Read: Powershell command to the Get Account expiration date, Extract user list which expires in a week time

It works, If you run a PowerShell script with run as administrator and needs to do the same on task scheduler to fix the issue, how to do this?

How can I execute the Scheduled task to run as Administrator?

  • Open scheduled task
  • Click properties of task
  • Go to Actions and select New and set the action to start a program.
  • Update below
  • Program/scripts: PowerShell.exe
  • Add arguments (optional): -ExecutionPolicy Bypass -File <Ps1 Script Location>
  • Click OK

Also Read: PowerShell command to extract Group policy result for a list of Servers

Through this way, we can run the PS1 script run as an Administrator on schedule task, if  PowerShell script only be work when executing it via Run as Administrator

Also Read: Enable Powershell Remoting on Windows server 2008 R2 and 2012

Run with highest privileges task scheduler

Also, try configuring task scheduler with the run with highest privileges

  • Open scheduled task
  • Click properties of task
  • In General tap
  • Select Run with highest privileges
  • Click OK

Also Read: Active Directory 2016 New Features

3 thoughts on “How to Run the PowerShell Script in Scheduled Task with Run as Administrator

  1. Jim Lane

    I don’t think this is correct. The option you are specifying has to do with restrictions on running unsigned scripts — it does not have anything to do with running a script using elevated privileges (aka “Run as Administrator”)

    Reply
  2. John Bivens

    Don’t forget you need to set your execution policy or it will not work.
    In powershell
    Set-executionpolicy unrestricted
    You can use Get-ExecutionPolicy -list to see how all of them are set

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *