-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExport-ScheduledTasks.ps1
56 lines (46 loc) · 1.51 KB
/
Export-ScheduledTasks.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<#
.SYNOPSIS
Export scheduled task list
.DESCRIPTION
ToDo
.PARAMETER OutDir
.EXAMPLE
.NOTES
## References
https://devblogs.microsoft.com/scripting/weekend-scripter-use-powershell-to-document-scheduled-tasks
tag: windows-only-script
#>
Param ([string] $OutDir)
# Generate CSV from task list
function GenerateCSVFromTasks([string] $taskPath, [string] $outCSVPath) {
Write-Host "Writing for scheduled task path $taskPath"
Get-ScheduledTask -TaskPath $taskPath |
ForEach-Object { [pscustomobject]@{
Name = $_.TaskName
Path = $_.TaskPath
LastResult = $(($_ | Get-ScheduledTaskInfo).LastTaskResult)
NextRun = $(($_ | Get-ScheduledTaskInfo).NextRunTime)
Status = $_.State
Command = $_.Actions.execute
Arguments = $_.Actions.Arguments }} | Format-Table
Get-ScheduledTask -TaskPath $taskPath |
ForEach-Object { [pscustomobject]@{
Name = $_.TaskName
Path = $_.TaskPath
LastResult = $(($_ | Get-ScheduledTaskInfo).LastTaskResult)
NextRun = $(($_ | Get-ScheduledTaskInfo).NextRunTime)
Status = $_.State
Command = $_.Actions.execute
Arguments = $_.Actions.Arguments }} |
Export-Csv -Append -Path $outCSVPath -NoTypeInformation
}
# Start of Main function
function Main() {
$csvFileName = $OutDir + '\SchTasks-' + $(Get-Date -Format "yyyy-MM-dd") + '.csv'
if (Test-Path $csvFileName) {
Clear-Content $csvFileName
}
GenerateCSVFromTasks '\' $csvFileName
GenerateCSVFromTasks '\fbit\' $csvFileName
}
Main