Scheduled Task that runs a PowerShell script returning 0x80070001

Scheduled Tasks showing the outcome of a task as 0x80070001

I've recently migrated several scheduled tasks from one machine to another as part of a rationalisation process. A couple of these tasks were ones that can only be run at a certain time, so were left to run according to their schedule. They also happened to be the only scheduled tasks that trigger PowerShell scripts.

Both tasks had return codes of 0x80070001 showing in the Scheduled Tasks console and the expected outputs and log files hadn't been created, other tasks that weren't running PowerShell scripts had run successfully, so a little bit of a mystery, especially as the detail for the Task Completed step was showing:

Task Scheduler successfully finished "{c2763d85-184a-4979-8f5f-07b2f77bda49}" instance of the "\My Scheduled Task" task for user "DOMAIN\username".

Attempting to run the task from a PowerShell console generated:

.\MyScript.ps1 : File E:\Services\Scripts\MyScript.ps1 cannot be loaded because running scripts
is disabled on this system. For more information, see about_Execution_Policies at
http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ .\MyScript.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

A ha! During configuration of the new server the execution policy wasn't changed using Set-ExecutionPolicy. Changing this allowed the scheduled task(s) to run without issue.

About Rob

I've been interested in computing since the day my Dad purchased his first business PC (an Amstrad PC 1640 for anyone interested) which introduced me to MS-DOS batch programming and BASIC.

My skillset has matured somewhat since then, which you'll probably see from the posts here. You can read a bit more about me on the about page of the site, or check out some of the other posts on my areas of interest.

No Comments

Add a Comment