为什么使用其他用户通过PowerShell创建的每周任务失败,错误为0x41306

前端之家收集整理的这篇文章主要介绍了为什么使用其他用户通过PowerShell创建的每周任务失败,错误为0x41306前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我们有一些脚本可以使用Power Shell创建预定作业,作为我们应用程序的一部分.最近测试它们时,我注意到它们中的一些总是立即失败,并且没有产生任何输出(它们甚至不出现在Get-Job列表中).

经过多天的调整,我们已经设法将它隔离到任何设定为每周运行的工作.下面是一个脚本,它创建两个完全相同的作业.当我们在我们的域上运行它,并提供域用户的凭据,然后强制两个作业在任务计划程序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:

https://connect.microsoft.com/PowerShell/feedback/details/776801/weekly-tasks-created-via-powershell-using-a-different-user-immediately-fail-with-error-0x41306

编辑:杰夫希克斯的一些额外信息

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.

我在创建计划任务时遇到了类似的问题,但我不记得它是否基于日程安排.我发现转换到gMSA帐户来运行我们的计划任务?这使我们能够设置运行用户是否登录的任务.否则,您必须提供用户名和密码,并且无法选择是否登录用户.
原文链接:https://www.f2er.com/windows/364996.html

猜你在找的Windows相关文章