I have a bunch of scheduled tasks set up in Windows Task Scheduler and I am trying to use Powershell to read the task metadata and determine whether the task has a trigger that will execute (or already has executed) on the current day. I'm using Powershell 5.0 on Microsoft Windows Server 2012 R2 Datacenter.
For Daily task triggers, it's straightforward as I can read the trigger's DaysInterval
property and if it's 1, then the task is Daily and will execute every day.
For Weekly task triggers, I'm stumped. I've tried getting the days of week like this:
$tasks = Get-ScheduledTask
foreach ($task in $tasks) {
foreach($trigger in $task.Triggers) {
$dows = $trigger.DaysOfWeek # doesn't work
$dows = $trigger.ScheduleByWeek.DaysOfWeek # doesn't work
}
}
I haven't even attempted with Monthly triggers.
My overall goal is to get a list of scheduled tasks that are scheduled to run (or have already run) on the current day. This would include tasks with Daily triggers, tasks with Weekly triggers whose set of days of the week contains the current day of the week, and tasks with Monthly triggers whose day of the month is the same as the day of the month today. I don't care about one-time triggers.