Share via

Query on Task Scheduler

Rising Flight 4,796 Reputation points
Sep 8, 2023, 10:35 PM

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,865 questions
Windows Server 2016
Windows Server 2016
A Microsoft server operating system that supports enterprise-level management updated to data storage.
2,552 questions
Windows Server 2012
Windows Server 2012
A Microsoft server operating system that supports enterprise-level management, data storage, applications, and communications.
1,612 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
13,517 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,597 questions
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 34,861 Reputation points
    Sep 9, 2023, 2:17 PM

    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: Newest
  1. Rising Flight 4,796 Reputation points
    Sep 11, 2023, 11:54 AM

    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.