Add local Windows Server inventory collection and validation; include core package
This commit is contained in:
20
powershell/Get-ServerTasks.ps1
Normal file
20
powershell/Get-ServerTasks.ps1
Normal file
@@ -0,0 +1,20 @@
|
||||
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.'
|
||||
}
|
||||
Reference in New Issue
Block a user