【问题标题】:Getting Scheduled Tasks Between Specific Times On Windows 10 Desktop在 Windows 10 桌面上获取特定时间之间的计划任务
【发布时间】:2018-03-12 15:16:14
【问题描述】:
我在 Windows 10 中使用 PowerShell 来获取特定的计划任务时遇到了一些麻烦。我需要获取在 9:00 PM 到 12 PM 之间运行的计划任务列表。我不知道如何正确使用“Get-ScheduledTask”和“Get-ScheduledTaskInfo”命令。
如果有人能帮助我以正确的方式编写脚本,我将不胜感激!
【问题讨论】:
标签:
windows
powershell
windows-10
scheduled-tasks
【解决方案1】:
我认为这是你需要的:
Get-ScheduledTask | ForEach-Object {
$NextRunTimeHour = ($_ | Get-ScheduledTaskInfo).NextRunTime.Hour
If ($NextRunTimeHour -in 21..23) { $_ }
}
获取计划任务,然后使用ForEach-Object 遍历它们,将每个任务通过管道传递到Get-ScheduledTaskInfo 以获取.NextRunTime 属性及其.Hour 子属性,然后如果小时为21、22 或返回计划任务23.
【解决方案2】:
其他方法,给你所有必要的信息:
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
}
}
}