3

When I use the PowerShell Cmdlet Get-ScheduledTaskInfo on a Windows server I get the following pieces of data

LastRunTime        : 22/04/1932 11:30:30
LastTaskResult     : 267011
NextRunTime        :
NumberOfMissedRuns : 0
TaskName           : \Microsoft\Windows\Workplace Join\Recovery-Check
TaskPath           :
PSComputerName     :

However, when I query the same scheduled task on the same Windows server using schtasks.exe I get far more information, as seen below.

HostName                             : ELT-W-PRD-AP-12
TaskName                             : \Microsoft\Windows\Workplace Join\Recovery-Check
Next Run Time                        : N/A
Status                               : Disabled
Logon Mode                           : Interactive/Background
Last Run Time                        : 30/11/1999 00:00:00
Last Result                          : 267011
Author                               : N/A
Task To Run                          : %SystemRoot%\System32\dsregcmd.exe /checkrecovery
Start In                             : N/A
Comment                              : Performs recovery check.
Scheduled Task State                 : Disabled
Idle Time                            : Disabled
Power Management                     :
Run As User                          : INTERACTIVE
Delete Task If Not Rescheduled       : Disabled
Stop Task If Runs X Hours and X Mins : 02:00:00
Schedule                             : Scheduling data is not available in this format.
Schedule Type                        : At logon time
Start Time                           : N/A
Start Date                           : N/A
End Date                             : N/A
Days                                 : N/A
Months                               : N/A
Repeat: Every                        : N/A
Repeat: Until: Time                  : N/A
Repeat: Until: Duration              : N/A
Repeat: Stop If Still Running        : N/A

How can I extract the same information from the scheduled task using PowerShell Cmdlets, rather than relying on schtasks.exe?

gerard
  • 835
  • 11
  • 27
  • 3
    By combining output from `Get-ScheduledTask` and `Get-ScheduledTaskInfo` – Mathias R. Jessen Mar 31 '22 at 13:22
  • I don't understand what you mean @MathiasR.Jessen. All that I get from `Get-ScheduledTask` is a list of scheduled tasks. So if I combine that with `Get-ScheduledTaskInfo` I will get the 7 values for each of the scheduled tasks. But I can get 28 different values for a scheduled task using `schtasks.exe`. – gerard Mar 31 '22 at 13:32
  • 2
    that's because of it's default formatting. PowerShell usually doesn't show more than it should. So look at the properties returned from `Get-ScheduledTaskInfo` and expand on them as they're properties, within properties too. `Get-ScheduledTask -TaskName usertask | Get-ScheduledTaskInfo | select *`, or `Get-ScheduledTask -TaskName usertask | Get-ScheduledTaskInfo | select -exp ciminstanceproperties`. – Abraham Zinala Mar 31 '22 at 13:36
  • Thanks for the responses above but I'm still confused. I got the `select *` working in conjunction with `Get-ScheduledTaskInfo` but that still only gives me the same information as I see without `select *` (i.e. LastRunTime, LastTaskResult, etc). How can I see information like `task to run` which is available via `schtasks.exe`? – gerard Apr 01 '22 at 11:12

1 Answers1

1

When you search with schtasks you used the /Verbose flag - you need to do the same here, then also say you want to view the entire list of retreived properties.

$info = Get-ScheduledTask -TaskName Test -Verbose | select -Property *
$info
write-host "Task's actions are" $info.actions "and triggers are" $info.Triggers
$runtimeInfo = Get-ScheduledTaskInfo $info.TaskName | select -property *
write-host "Last runtime info is" $runtimeInfo

edit: Get-ScheduledTaksInfo will only provide:

the last run-time information for a scheduled task.

Mike Anthony
  • 429
  • 3
  • 9