Task scheduler scripts

Glenn Maxwell 11,841 Reputation points
2024-04-07T23:46:54.6566667+00:00

Hi All

i have 100 plus scripts running on a VM. i have task schedulers running daily, for few weekly. i want to export all the task scheduler scripts to a csv file. using the below syntax i am able to export

$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
        LastTaskResult = $taskinfo.LastTaskResult
    }
}
$data | Export-Csv c:\windows\temp\TS.csv -NoTypeInformation

i want to export the below information as well, please guide me how to get this information.

Under Actions Tab for a task:  
Action: Program/script:  
Add aurugments(optional)  
Start in (optional)
Windows Server 2019
Windows Server 2019
A Microsoft server operating system that supports enterprise-level management updated to data storage.
3,832 questions
Windows Server 2016
Windows Server 2016
A Microsoft server operating system that supports enterprise-level management updated to data storage.
2,536 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
13,387 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,576 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,682 questions
{count} votes

Accepted answer
  1. Ian Xue 38,551 Reputation points Microsoft Vendor
    2024-04-09T05:49:45.64+00:00

    Hi Glenn Maxwell,

    These can be found in the Actions property of the task object.

    $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
            LastTaskResult = $taskinfo.LastTaskResult
    		Execute = $task.Actions.Execute
    		Arguments = $task.Actions.Arguments
    		WorkingDirectory= $task.Actions.WorkingDirectory
        }
    }
    $data | Export-Csv c:\windows\temp\TS.csv -NoTypeInformation
    

    Best Regards,

    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.

    0 comments No comments

0 additional answers

Sort by: Most helpful

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.