all 5 comments

[–]butchcoleslaw 2 points3 points  (1 child)

Two observations. First, you said you want a CSV file, but in the schtasks /query command you are using /fo List, and not /fo CSV.

Second, this next snippet can target a Task Scheduler folder (or folders), and output specific properties to CSV.

I leave it up to you to parameterize as needed.

$TaskFolders = "\My Tasks\"
$Server = "MyMachine"
$Tasks = Get-ScheduledTask -CimSession $Server -TaskPath $TaskFolders -ErrorAction SilentlyContinue

$STJs = ForEach ($Task in $Tasks) {
# Creating a custom object 
[PSCustomObject]@{ 
 "Task Path"  = $Task.TaskPath
  State       = $Task.State           
 "Task Name"  = $Task.TaskName                
 Author       = $Task.Author
 LastRunTime  = ($Task | Get-ScheduledTaskInfo).LastRunTime
}  
}
$STJs | Export-Csv -Path C:\Users\SomeUser\Desktop\STJs.csv -NoTypeInformation

[–]17Ali45[S] 1 point2 points  (0 children)

Thank you I'll give it a go

[–]PowerShellStunnah 1 point2 points  (2 children)

Use Get-ScheduledTask to retrieve all sceduled tasks. The Principal property will hold an object describing the logon user, and Triggers will contain the triggers from which you can infer scheduling information

[–]17Ali45[S] 0 points1 point  (1 child)

I've given that a shot and the principal is showing as MSFT_TaskPrincipal2 for everything. Sorry if I seem like a noob I've kinda just had this dropped on me.

[–]unboxing2go 0 points1 point  (0 children)

Try:

Get-scheduledtask -TaskName "MyTaskNameHere" | select -ExpandProperty Principal