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?
CodePudding user response:
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.