经过多天的调整,我们已经设法将它隔离到任何设定为每周运行的工作.下面是一个脚本,它创建两个完全相同的作业.当我们在我们的域上运行它,并提供域用户的凭据,然后强制两个作业在任务计划程序GUI中运行(右键单击 – >运行),每日运行正常(0x0结果)和每周一个失败(0x41306).
注意:如果我不提供-Credential参数,则两个作业都可以正常工作.如果任务是每周一次,并且以该域用户身份运行,则作业仅会失败.
我无法找到有关这种情况发生的原因的信息,也没有想到任何原因会导致每周工作的表现不同.任务计划程序中的“历史记录£”选项卡几乎没有任何有用的信息,只是“由于用户请求而停止的任务”和“任务已终止”,两者都没有有用的信息:
Task Scheduler terminated “{eabba479-f8fc-4f0e-bf5e-053dfbfe9f62}”
instance of the “\Microsoft\Windows\PowerShell\ScheduledJobs\Test1″
task. Task Scheduler stopped instance
“{eabba479-f8fc-4f0e-bf5e-053dfbfe9f62}” of task
“\Microsoft\Windows\PowerShell\ScheduledJobs\Test1” as request by
user “MyDomain\SomeUser” .
怎么了?为什么每周任务的运行方式不同,我该如何解决这个问题呢?
这是Windows Server 2008 R2上的PowerShell v3.我一直无法在本地重现这一点,但我没有像我们的生产域中那样设置用户(我正在研究这个,但我想发布这个ASAP希望有人知道发生了什么!).
Import-Module PSScheduledJob $Action = { "Executing job!" } $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)
编辑:按照snover的建议添加到Connect:
编辑:杰夫希克斯的一些额外信息
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.