< Summary - Kestrun — Combined Coverage

Information
Class: Public.Server.Get-KrServer
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Server/Get-KrServer.ps1
Tag: Kestrun/Kestrun@5f1d2b981c9d7292c11fd448428c6ab6c811c5de
Line coverage
60%
Covered lines: 6
Uncovered lines: 4
Coverable lines: 10
Total lines: 71
Line coverage: 60%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 11/19/2025 - 17:40:50 Line coverage: 0% (0/10) Total lines: 71 Tag: Kestrun/Kestrun@fcf33342333cef0516fe0d0912a86709874fd02604/04/2026 - 18:57:31 Line coverage: 60% (6/10) Total lines: 71 Tag: Kestrun/Kestrun@25c95cfbd84df534a61ed03b9abab034ac673a75

Coverage delta

Coverage delta 60 -60

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Server/Get-KrServer.ps1

#LineLine coverage
 1<#
 2.SYNOPSIS
 3    Gets the current Kestrun server instance.
 4.DESCRIPTION
 5    This function retrieves the current Kestrun server instance. If a server instance is not provided,
 6    it attempts to resolve the server from the current context.
 7.PARAMETER Server
 8    The Kestrun server instance to retrieve. If not specified, the function will attempt to resolve the current server c
 9.PARAMETER StartTime
 10    If specified, returns the server's start time as a DateTime object.
 11.PARAMETER StopTime
 12    If specified, returns the server's stop time as a DateTime object.
 13.PARAMETER Uptime
 14    If specified, returns the server's uptime as a TimeSpan object.
 15.EXAMPLE
 16    Get-KrServer
 17    This command retrieves the current Kestrun server instance.
 18.EXAMPLE
 19    Get-KrServer -StartTime
 20    This command retrieves the start time of the current Kestrun server instance.
 21.EXAMPLE
 22    Get-KrServer -StopTime
 23    This command retrieves the stop time of the current Kestrun server instance.
 24.EXAMPLE
 25    Get-KrServer -Uptime
 26    This command retrieves the uptime of the current Kestrun server instance.
 27.OUTPUTS
 28    [Kestrun.Hosting.KestrunHost]
 29        The current Kestrun server instance.
 30    [DateTime]
 31        The server's start time or stop time if the corresponding switch is used.
 32    [TimeSpan]
 33        The server's uptime if the Uptime switch is used.
 34.NOTES
 35    This function is part of the Kestrun PowerShell module and is used to manage Kestrun server instances.
 36    If the server instance is not found in the context, it attempts to resolve it using the Resolve-KestrunServer functi
 37#>
 38function Get-KrServer {
 39    [KestrunRuntimeApi('Everywhere')]
 40    [CmdletBinding(DefaultParameterSetName = 'Default')]
 41    [OutputType([Kestrun.Hosting.KestrunHost])]
 42    [OutputType([DateTime])]
 43    [OutputType([TimeSpan])]
 44    param(
 45        [Parameter(ValueFromPipeline)]
 46        [Kestrun.Hosting.KestrunHost]$Server,
 47        [Parameter(ParameterSetName = 'StartTime')]
 48        [switch]$StartTime,
 49        [Parameter(ParameterSetName = 'StopTime')]
 50        [switch]$StopTime,
 51        [Parameter(ParameterSetName = 'Uptime')]
 52        [switch]$Uptime
 53    )
 54    process {
 155        if ($null -eq $Context -or $null -eq $Context.Response) {
 156            $Server = Resolve-KestrunServer -Server $Server
 57        } else {
 058            $Server = $Context.Host
 59        }
 60
 161        if ($StartTime.IsPresent) {
 062            return $Server.Runtime.StartTime
 163        } elseif ($StopTime.IsPresent) {
 064            return $Server.Runtime.StopTime
 165        } elseif ($Uptime.IsPresent) {
 066            return $Server.Runtime.Uptime
 67        } else {
 168            return $Server
 69        }
 70    }
 71}

Methods/Properties

Get-KrServer()