Query on Task Scheduler

Rising Flight 4,596 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 Server 2019
Windows Server 2019
A Microsoft server operating system that supports enterprise-level management updated to data storage.
3,757 questions
Windows Server 2016
Windows Server 2016
A Microsoft server operating system that supports enterprise-level management updated to data storage.
2,511 questions
Windows Server 2012
Windows Server 2012
A Microsoft server operating system that supports enterprise-level management, data storage, applications, and communications.
1,591 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
13,113 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,532 questions
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 33,916 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 4,596 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.