Windows PowerShell Home
Weekly tasks created via PowerShell using a different user immediately fail with error 0x41306
1/17/2013 8:22:55 AM
User(s) can reproduce this bug
(Edit: Confirmed that this happens on Windows Server 2008 R2, Windows Server 2012, Windows 8)
I've posted full details and a sample on StackOverflow here:
We're using PowerShell to create some scheduled jobs, but those that are set to be weekly instead of daily (using New-JobTrigger) always immediately fail with an exist code of 0x41306 when we try to execute them from the Task Scheduler UI. (However they seem to work in PowerShell if we use (Get-ScheduledJob x).Run()
In the repo steps is a script to create two identical tasks; one running daily, one weekly. Forcing them in the Task Scheduler UI will show this issue (one will run and have exit code of 0, the other 0x41306).
We're using Windows Server 2008 R2. Jeff Hicks has tested this on Windows 8 and says the same thing occurs there. If we don't pass the -Credential to it, it doesn't seem to happen.
Some additional info from Jeff Hicks:
I used your code to create the same jobs on my 2008 R2 box running PS v3. Both jobs ran fine from PowerShell using Start-Job. But in the GUI, I got the same error for the weekly job.
I get the same result on Windows 8. Something is telling the task service to abort. I tested some other settings but they had no effect. I looked through all of the logs I could think of and all they show is the job starting, PowerShell loading and then the task scheduler cancelling.
I reset the weekly task to run today a little bit ago and it still failed. I also tested a weekly task doing something other than PowerShell and it ran just fine.
I changed the weekly job to use the same account as the current user and it ran just fine. Changed it back to the other account and it failed again. I have no idea about the correlation between the trigger and account.
How often does this happen?
Have you seen this problem before in this product?
I don't know if this issue existed previously
1. Run the below script on a Windows Server 2008 R2 box. Enter credentials of a domain user when prompted.
2. Once created, right click on each job in the Task Scheduler UI and select "Run".
3. Refresh the window to see the last run results
4. Cry, because the weekly one failed immediately and logged nothing useful, and the daily one worked fine.
5. Running "Get-Job" will show the successful run, but the weekly one is nowhere to be found.
$cred = Get-Credential "MyDomain\SomeUser"
# Remove previous versions (to allow re-running this script)
Get-ScheduledJob Test1 | Unregister-ScheduledJob
Get-ScheduledJob Test2 | Unregister-ScheduledJob
# Create two identical jobs, with different triggers
Register-ScheduledJob "Test1" -ScriptBlock $Action -Credential $cred -Trigger (New-JobTrigger -Weekly -At 1:25am -DaysOfWeek Sunday)
Register-ScheduledJob "Test2" -ScriptBlock $Action -Credential $cred -Trigger (New-JobTrigger -Daily -At 1:25am)
I expect both tasks to run correctly and exit with a 0 error code, and both be accessible in PowerShell when I type Get-Job.
to post a comment.
Please enter a comment.
to post a workaround.
Please enter a workaround.
© 2013 Microsoft