• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by User Bot


26 Apr, 2025

Updated at 20 May, 2025

Powershell WMI Querry Task Scheduler "MSFT_TaskDynamicInfo"

I have figured out how to use PowerShell with task scheduler to give me what I am looking for. However, I am unable to figure out how to do this with a wmi query so we can pull this information from machines not PowerShell friendly.

This gives me what I am wanting:

$MyScheduleTask = (Get-ScheduledTask) | `
                            Where-Object {$_.Actions | Where-Object {$_.Execute -like "*$executable*"} } | `
                                select  TaskName,
                                        TaskPath,
                                        State,
                                        @{n='LastRunTime';e={($_ | Get-ScheduledTaskInfo).LastRunTime}},
                                        @{n='NextRunTime';e={($_ | Get-ScheduledTaskInfo).NextRunTime}},
                                        @{n='Triggers';e={$_.Triggers.StartBoundary}},@{n='DaysOfWeek';
                                        e={$_.Triggers.DaysOfWeek}},
                                        @{n='WeeksIntervall';
                                        e={$_.Triggers.WeeksInterval}},
                                        @{n='Execute';
                                        e={$_.Actions.Execute}},
                                        @{n='Arguments';
                                        e={$_.Actions.Arguments}}

What I am trying to do is the same thing with a WMI Querry:

$MyScheduleTask = (Get-ScheduledTask) | `
                                Where-Object {$_.Actions | Where-Object {$_.Execute -like "*$executable*"} } | `
                                    select  TaskName,
                                            TaskPath,
                                            State,
                                            @{n='LastRunTime';e={($_ | Get-ScheduledTaskInfo).LastRunTime}},
                                            @{n='NextRunTime';e={($_ | Get-ScheduledTaskInfo).NextRunTime}},
                                            @{n='Triggers';e={$_.Triggers.StartBoundary}},@{n='DaysOfWeek';
                                            e={$_.Triggers.DaysOfWeek}},
                                            @{n='WeeksIntervall';
                                            e={$_.Triggers.WeeksInterval}},
                                            @{n='Execute';
                                            e={$_.Actions.Execute}},
                                            @{n='Arguments';
                                            e={$_.Actions.Arguments}}

So far my research has worked for me except for the Dynamic values of [LastRunTime] and [NextRunTime]. In my research from: https://wutils.com/wmi/root/microsoft/windows/taskscheduler/default.html it looks like "MSFT_TaskDynamicInfo" Class holds the information I am wanting. However everytime I run it I get a null responce.

 (Get-ScheduledTask) | Where-Object {$_.Actions | Where-Object {$_.Execute -like "*shutdown*"} }
                                                               
$wmiObject = Get-WmiObject -Namespace "ROOT\Microsoft\Windows\TaskScheduler" -Query "SELECT * FROM MSFT_TaskDynamicInfo WHERE TaskName='Restart Computer' AND TaskPath='\'"
    Write-Host $wmiObject.LastRunTime # or other property name, see properties

Schedule task exists:

TaskPath                                       TaskName                          State     
--------                                       --------                          -----     
\                                              Restart Computer                  Ready  

Any suggestions on how to get the last and next runtime using wmi?