Task scheduler scripts

Glenn Maxwell 10,146 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,489 questions
Windows Server 2016
Windows Server 2016
A Microsoft server operating system that supports enterprise-level management updated to data storage.
2,393 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,236 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,397 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,125 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 30,861 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