GetScheduledTaskInfo NextRunTime 错误 [英] GetScheduledTaskInfo NextRunTime is wrong

查看:50
本文介绍了GetScheduledTaskInfo NextRunTime 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Powershell 获取某些计划任务的 NextRunTime.我正在检索这些值,但它们与我在任务计划程序管理控制台中看到的不匹配.

I'm trying to use Powershell to get the NextRunTime for some scheduled tasks. I'm retrieving the values but they don't match up to what I'm seeing in the Task Scheduler Management Console.

例如,在 Task Scheduler 控制台中,我的TestTask"的 Next Run Time 值为1/9/2018 12:52:30 PM".但是当我在 Powershell 中执行以下调用时,它会为 NextRunTime 显示12:52:52 PM".

For example, in the Task Scheduler console my "TestTask" has a Next Run Time value of "1/9/2018 12:52:30 PM". But when I do the following call in Powershell it shows "12:52:52 PM" for the NextRunTime.

Get-ScheduledTask -TaskName "TestTask" | Get-ScheduledTaskInfo

据我所知,从 PowerShell Get-ScheduledTaskInfo cmdlet 返回时,秒值始终与分钟值相同.我想知道该 cmdlet 中是否存在时间格式错误(hh:mm:mm 而不是 hh:mm:ss),但我不知道如何查找.该任务正在控制台中显示的确切时间运行,因此我认为这是 powershell 调用的问题.

From what I've seen the seconds value is always the same value as the minutes when returned from the PowerShell Get-ScheduledTaskInfo cmdlet. I'm wondering if there's a time formatting error (hh:mm:mm instead of hh:mm:ss) in that cmdlet but I have no idea how to look for that. The task is running at the exact time shown in the console so that makes me think that it's an issue with the powershell call.

有没有人见过这个问题并且知道如何在 PowerShell 中获取正确的 NextRunTime 值?我也发现 LastRunTime 值存在同样的问题.

Has anyone seen this issue before and know how to get the correct NextRunTime value in PowerShell? I'm also seeing the same issue with the LastRunTime value.

我已经在 Windows Server 2016 和 Windows 10 上尝试过这个,并且在两个操作系统上都得到了相同的结果.

I've tried this on Windows Server 2016 and Windows 10 and get the same results on both operating systems.

推荐答案

我可以确认我在 Server 2012R2 上也看到了同样的问题.您可以通过使用任务调度程序 COM 对象、获取根文件夹(或您的任务存储在其中的任何文件夹,但很可能在根文件夹中),然后从中获取任务信息来获取正确的信息.这样做的方法如下:

I can confirm that I see the same issue on Server 2012R2 as well. You can get the correct information by using the task scheduler COM object, getting the root folder (or whatever folder your task is stored in, but most likely its in the root folder), and then getting the task info from that. Here's how you'd do it:

$Scheduler = New-Object -ComObject Schedule.Service
$Scheduler.Connect()
$RootFolder = $Scheduler.GetFolder("\")
$Task = $RootFolder.GetTask("TestTask")
$Task.NextRunTime

可能还值得注意的是,您可以使用 Connect() 方法连接到其他计算机上的任务调度程序(如果您有权访问他们的任务调度程序),并获取有关其任务的信息、停止或开始他们的任务、创建新任务……如果您不介意不使用 *-ScheduledTask* cmdlet,这里有很多好东西.

Probably also worth noting that you can use the Connect() method to connect to the task scheduler on other computers (if you have rights to access their task scheduler), and get information about their tasks, stop or start their tasks, make new tasks... lots of good stuff here if you don't mind not using the *-ScheduledTask* cmdlets.

这篇关于GetScheduledTaskInfo NextRunTime 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆