Thursday, 18 December 2014

Run Powershell Script in Task Scheduler

Run Powershell Script in Task Scheduler

 
If you ever find yourself in need of running a powershell script as a scheduled task, ensure the Action tab settings are set up as follows:
  • Program/Script: Point this to the location of the powershell executable (this'll be  %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe)
  •  
  • Add arguments (optional): Enter the file path to the script you want to be run

 
Other things to check should the scheduled task fail:
  • Is the 'Run with highest privileges' option checked on the General tab?
  • Is the task set to 'Run whether user is logged or not' on the General tab?
  • If you created it in PowerGUI or some similar editing tool, did that application automatically load any modules - if so, you'll need to add a line to your script to load said modules (e.g. Add-PSSnapin Quest.ActiveRoles.ADManagement)
  • Manually run your scheduled task and have a look at the last run result code in the Task Scheduler main window. Use the mighty Google to see what the result means
  • Also, check the History tab and see what info has popped in there:



1 comment: