Saturday, October 15, 2016

Clustered task in Windows server 2012 R2 with 0x1 error

I tried to create a clustered task and got 0x1 error, according to M$ it means

0x1: An incorrect function was called or an unknown function was called. (ref:

This is the original script that generated 0x1 error

$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "runme.ps1" -WorkingDirectory "E:\Shares\scripts"

E: is a clustered disk and I got 0x1 error when I execute the task manually.

Later I found that it has to do with execution policy, so I have changed it to

$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-executionpolicy bypass -file runme.ps1" -WorkingDirectory "E:\Shares\scripts"

and it ran without error.

Here is the complete script to create the task
$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-executionpolicy bypass -file runme.ps1" -WorkingDirectory "E:\Shares\scripts"
$trigger = New-ScheduledTaskTrigger -Daily -At 3pm
Register-ClusteredScheduledTask –Cluster filesharecluster –TaskName MyResourceSpecificTask –TaskType ResourceSpecific –Resource "cluster disk 2" –Action $action –Trigger $trigger

and this is what the runme.ps1 looks like, as you can see you can run dos command and powershell

dir c:\ | export-csv "e:\shares\scripts\result.csv"

somehow trying to to run bat file also generated 0x1 error, some suggested that the account that runs the task needs to be in "logon as a batch" job in local security policy but I have not tried it yet.

No comments: