Query on Task Scheduler

Rising Flight 5,216 Reputation points
2023-09-08T22:35:23.2266667+00:00

Hi All

i have an Azure VM which is running on Windows Server 2012R2. Under Task Scheduler it has many folders and every folder has tasks i.e many PowerShell scripts are running. Many are scheduled and running daily. few are disabled. I want to export all the tasks which are scheduled and running also when was it last ran. How do i export this information. I want to upgrade this VM to Windows Server 2019 and after upgrade i can validate these scheduled scripts are running fine or not. Almost i have 100 tasks and i dont know which are running. it is hard to go to each folder and check Experts guide me.

Windows for business | Windows Server | User experience | PowerShell
Windows for business | Windows Server | User experience | Other
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 36,291 Reputation points
    2023-09-09T14:17:36.6233333+00:00

    This script will export the data to a csv. Just add in any more fields that you want to save.

    $data = @()
    foreach ( $task in (Get-ScheduledTask)) { 
        $taskinfo = Get-ScheduledTaskInfo $task
        $data += [PSCustomObject]@{
            Name = $task.TaskName
            Path = $task.TaskPath
            Enabled = $task.Settings.Enabled
            LastRun = $taskinfo.LastRunTime
            NextRun = $taskinfo.NextRunTime
        }
    }
    $data | Export-Csv c:\temp\tasks.csv -NoTypeInformation
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Rising Flight 5,216 Reputation points
    2023-09-11T11:54:24.2166667+00:00

    How to know last run job was successful or not.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.