| | 1 | | <# |
| | 2 | | .SYNOPSIS |
| | 3 | | Returns a snapshot of the current schedule. |
| | 4 | | .DESCRIPTION |
| | 5 | | This function retrieves the current schedule snapshot, including all scheduled jobs and their next run times. |
| | 6 | | .PARAMETER Server |
| | 7 | | The Kestrun host object containing the scheduler. |
| | 8 | | .PARAMETER Name |
| | 9 | | Optional job name filter. If specified, only jobs matching the name will be returned. |
| | 10 | | .PARAMETER TimeZoneId |
| | 11 | | Optional Windows / IANA time-zone id to convert timestamps. |
| | 12 | | Example: "Pacific Standard Time" or "Europe/Berlin" |
| | 13 | | .PARAMETER AsHashtable |
| | 14 | | If set, returns a hashtable instead of a ScheduleReport object. |
| | 15 | | .EXAMPLE |
| | 16 | | Get-KrScheduleSnapshot -Server $myServer |
| | 17 | | Retrieves the schedule snapshot from the specified Kestrun server. |
| | 18 | | .EXAMPLE |
| | 19 | | Get-KrScheduleSnapshot -Server $myServer -Name 'Cache' |
| | 20 | | Retrieves the schedule snapshot for the job named 'Cache'. |
| | 21 | | .EXAMPLE |
| | 22 | | Get-KrScheduleSnapshot -Server $myServer -TimeZoneId "Europe/Berlin" |
| | 23 | | Retrieves the schedule snapshot with timestamps converted to the specified time zone. |
| | 24 | | .EXAMPLE |
| | 25 | | Get-KrScheduleSnapshot -Name 'ps-*' -TimeZoneId 'Pacific Standard Time' |
| | 26 | | Retrieves all jobs matching the pattern 'ps-*' with timestamps converted to Pacific Standard Time. |
| | 27 | | .OUTPUTS |
| | 28 | | Returns a ScheduleReport object or a hashtable if AsHashtable is set. |
| | 29 | | #> |
| | 30 | | function Get-KrScheduleSnapshot { |
| | 31 | | [KestrunRuntimeApi('Everywhere')] |
| | 32 | | [CmdletBinding()] |
| | 33 | | [OutputType([Kestrun.Scheduling.JobInfo[]])] |
| | 34 | | [OutputType([Hashtable])] |
| | 35 | | param( |
| | 36 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | 37 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | 38 | | [string[]]$Name, |
| | 39 | | [string]$TimeZoneId, |
| | 40 | | [switch]$AsHashtable |
| | 41 | | ) |
| | 42 | | begin { |
| | 43 | | # Ensure the server instance is resolved |
| 0 | 44 | | $Server = Resolve-KestrunServer -Server $Server |
| 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 | | $jobs = $Server.Scheduler.GetSnapshot() |
| | 51 | |
|
| 0 | 52 | | if (-not $AsHashtable) { |
| 0 | 53 | | return $jobs # strongly-typed JobInfo records |
| | 54 | | } |
| | 55 | |
|
| | 56 | | # PowerShell-friendly shape |
| 0 | 57 | | return $jobs | ForEach-Object { |
| 0 | 58 | | [ordered]@{ |
| 0 | 59 | | Name = $_.Name |
| 0 | 60 | | LastRunAt = $_.LastRunAt |
| 0 | 61 | | NextRunAt = $_.NextRunAt |
| 0 | 62 | | IsSuspended = $_.IsSuspended |
| | 63 | | } |
| | 64 | | } |
| | 65 | |
|
| 0 | 66 | | $tz = if ($TimeZoneId) { |
| 0 | 67 | | [TimeZoneInfo]::FindSystemTimeZoneById($TimeZoneId) |
| 0 | 68 | | } else { [TimeZoneInfo]::Utc } |
| | 69 | |
|
| 0 | 70 | | $Server.Scheduler.GetSnapshot($tz, $AsHashtable, $Name) |
| | 71 | | } |
| | 72 | | } |
| | 73 | |
|