| | 1 | | <# |
| | 2 | | .SYNOPSIS |
| | 3 | | Returns the full schedule report. |
| | 4 | | .DESCRIPTION |
| | 5 | | This function retrieves the current schedule report, including all scheduled jobs and their next run times. |
| | 6 | | .PARAMETER Server |
| | 7 | | The Kestrun host object containing the scheduler. |
| | 8 | | .PARAMETER TimeZoneId |
| | 9 | | Optional Windows / IANA time-zone id to convert timestamps. |
| | 10 | | Example: "Pacific Standard Time" or "Europe/Berlin" |
| | 11 | | .PARAMETER AsHashtable |
| | 12 | | If set, returns a hashtable instead of a ScheduleReport object. |
| | 13 | | .EXAMPLE |
| | 14 | | Get-KrScheduleReport -Server $myServer |
| | 15 | | Retrieves the schedule report from the specified Kestrun server. |
| | 16 | | .EXAMPLE |
| | 17 | | Get-KrScheduleReport -Server $myServer -TimeZoneId "Europe/Berlin" |
| | 18 | | Retrieves the schedule report with timestamps converted to the specified time zone. |
| | 19 | | .OUTPUTS |
| | 20 | | Returns a ScheduleReport object or a hashtable if AsHashtable is set. |
| | 21 | | #> |
| | 22 | | function Get-KrScheduleReport { |
| | 23 | | [KestrunRuntimeApi('Everywhere')] |
| | 24 | | [CmdletBinding()] |
| | 25 | | [OutputType([Kestrun.Scheduling.ScheduleReport])] |
| | 26 | | [OutputType([Hashtable])] |
| | 27 | | param( |
| | 28 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | 29 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | 30 | | [string]$TimeZoneId, |
| | 31 | | [switch]$AsHashtable |
| | 32 | | ) |
| | 33 | | begin { |
| 0 | 34 | | if (-not $Server) { |
| 0 | 35 | | if ($KestrunHost) { |
| 0 | 36 | | Write-KrInfoLog "No server specified, using global KestrunHost variable.($KestrunHost)" |
| | 37 | | # If no server is specified, use the global $KestrunHost variable |
| | 38 | | # This is useful for scripts that run in the context of a Kestrun server |
| 0 | 39 | | $Server = $KestrunHost |
| | 40 | | } else { |
| | 41 | | # Ensure the server instance is resolved |
| 0 | 42 | | $Server = Resolve-KestrunServer -Server $Server |
| | 43 | | } |
| | 44 | | } |
| 0 | 45 | | if ($null -eq $Server) { |
| 0 | 46 | | throw 'Server is not initialized. Please ensure the server is configured before setting options.' |
| | 47 | | } |
| | 48 | | } |
| | 49 | | process { |
| 0 | 50 | | if (-not $Server.Scheduler) { |
| 0 | 51 | | throw 'SchedulerService is not enabled.' |
| | 52 | | } |
| | 53 | |
|
| 0 | 54 | | $tz = if ($TimeZoneId) { |
| 0 | 55 | | [TimeZoneInfo]::FindSystemTimeZoneById($TimeZoneId) |
| 0 | 56 | | } else { [TimeZoneInfo]::Utc } |
| | 57 | |
|
| 0 | 58 | | if ($AsHashtable) { |
| 0 | 59 | | return $Server.Scheduler.GetReportHashtable($tz) |
| | 60 | | } else { |
| 0 | 61 | | return $Server.Scheduler.GetReport($tz) |
| | 62 | | } |
| | 63 | | } |
| | 64 | | } |
| | 65 | |
|