21 lines
1.6 KiB
PowerShell
21 lines
1.6 KiB
PowerShell
function Get-SamsaraTasks {
|
|
param($Result)
|
|
Invoke-SamsaraRead $Result 'Scheduled tasks' {
|
|
$Result.data = @(Get-ScheduledTask -ErrorAction Stop | ForEach-Object {
|
|
$task = $_
|
|
$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) })
|
|
[pscustomobject]@{ name = [string]$task.TaskName; path = [string]$task.TaskPath
|
|
enabled = [bool]$task.Settings.Enabled; state = [string]$task.State
|
|
account = [string]$task.Principal.UserId; executables = ($executables -join '; ')
|
|
triggers = if ($triggers.Count) { $triggers -join ' | ' } else { 'No trigger metadata visible; manual or external invocation remains possible' } }
|
|
})
|
|
}
|
|
$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.'
|
|
}
|