简体   繁体   English

在Windows 10桌面上的特定时间之间获取计划任务

[英]Getting Scheduled Tasks Between Specific Times On Windows 10 Desktop

I'm having some troubles using the PowerShell in windows 10 in order to get specific scheduled tasks. 为了获取特定的计划任务,在Windows 10中使用PowerShell遇到了一些麻烦。 I need to get a list of scheduled task that run between 9:00 PM to 12 PM. 我需要获取在9:00 PM到12 PM之间运行的计划任务的列表。 I couldn't figure out how to use the “Get-ScheduledTask “ and “Get-ScheduledTaskInfo” commands properly. 我不知道如何正确使用“ Get-ScheduledTask”和“ Get-ScheduledTaskInfo”命令。 I will be so grateful if someone can help me writing the script the right way! 如果有人可以帮助我以正确的方式编写脚本,我将非常感激!

I think this is what you need: 我认为这是您需要的:

Get-ScheduledTask | ForEach-Object {
    $NextRunTimeHour = ($_ | Get-ScheduledTaskInfo).NextRunTime.Hour
    If ($NextRunTimeHour -in 21..23) { $_ }
}

Gets the Scheduled Tasks, then iterates through them with ForEach-Object , piping each to Get-ScheduledTaskInfo to get the .NextRunTime property and it's .Hour subproperty and then returning the Scheduled task if the hour is 21, 22 or 23. 获取计划任务,然后使用ForEach-Object遍历它们,将每个管道传递给Get-ScheduledTaskInfo以获取.NextRunTime属性及其.Hour子属性,如果小时是21、22或23,则返回计划任务。

Other method, give you all necessary infos : 其他方法,为您提供所有必要的信息:

Get-ScheduledTask| %{$taskName=$_.TaskName; $_.Triggers | 
where {$_ -ne $null -and $_.Enabled -eq $true -and $_.StartBoundary -ne $null -and ([System.DateTime]$_.StartBoundary).Hour -in 21..23} |  %{ 
[pscustomobject]@{
Name=$taskName; 
trigger=$_
Enabled=$_.Enabled
EndBoundary=$_.EndBoundary
ExecutionTimeLimit=$_.ExecutionTimeLimit
Id=$_.Id
Repetition=$_.Repetition
StartBoundary=$_.StartBoundary
DaysInterval=$_.DaysInterval
RandomDelay=$_.RandomDelay
PSComputerName=$_.PSComputerName
}

}

} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM