26 lines
2.0 KiB
PowerShell
26 lines
2.0 KiB
PowerShell
function Get-SamsaraTasks {
|
|
param($Result)
|
|
Invoke-SamsaraRead $Result 'Scheduled tasks' {
|
|
$tasks = @(Get-ScheduledTask -ErrorAction Stop)
|
|
foreach ($task in $tasks) {
|
|
Invoke-SamsaraRead $Result 'Scheduled task metadata projection' {
|
|
if ($null -eq $task -or [string]::IsNullOrEmpty([string]$task.TaskName)) { throw 'Missing task identity' }
|
|
$triggers = @($task.Triggers | ForEach-Object {
|
|
$type = if ($_.CimClass) { [string]$_.CimClass.CimClassName } else { 'Unknown trigger' }
|
|
# Select only known scheduler metadata; never serialize entire CIM objects.
|
|
$repetition = if ($_.Repetition) { [string]$_.Repetition.Interval } else { '' }
|
|
'{0}; start={1}; enabled={2}; daysInterval={3}; weeksInterval={4}; daysOfWeek={5}; repeat={6}' -f $type, $_.StartBoundary, $_.Enabled, $_.DaysInterval, $_.WeeksInterval, $_.DaysOfWeek, $repetition
|
|
})
|
|
$executables = @($task.Actions | ForEach-Object { Get-SamsaraSafeExecutable ([string]$_.Execute) })
|
|
$row = [pscustomobject]@{ name = [string]$task.TaskName; path = [string]$task.TaskPath
|
|
enabled = [bool]$task.Settings.Enabled; state = [string]$task.State
|
|
account = if ($task.Principal.UserId) { [string]$task.Principal.UserId } else { [string]$task.Principal.GroupId }; executables = ($executables -join '; ')
|
|
triggers = if ($triggers.Count) { $triggers -join ' | ' } else { 'No trigger metadata visible; manual or external invocation remains possible' } }
|
|
$null = ConvertTo-Json -InputObject $row -Depth 4 -ErrorAction Stop
|
|
$Result.data += $row
|
|
}
|
|
}
|
|
}
|
|
$Result.limitations += 'Visible Task Scheduler registrations only. Arguments, inline scripts, task XML, event queries and execution history are omitted. Non-executable actions may lack an executable name. Trigger fields are descriptive, not a prediction of execution.'
|
|
}
|