< Summary - Kestrun — Combined Coverage

Information
Class: Public.Certificate.Export-KrCertificate
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Certificate/Export-KrCertificate.ps1
Tag: Kestrun/Kestrun@5f1d2b981c9d7292c11fd448428c6ab6c811c5de
Line coverage
0%
Covered lines: 0
Uncovered lines: 9
Coverable lines: 9
Total lines: 59
Line coverage: 0%
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/9) Total lines: 52 Tag: Kestrun/Kestrun@fcf33342333cef0516fe0d0912a86709874fd02604/19/2026 - 15:52:57 Line coverage: 0% (0/9) Total lines: 59 Tag: Kestrun/Kestrun@765a8f13c573c01494250a29d6392b6037f087c9

Coverage delta

Coverage delta 1 -1

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Certificate/Export-KrCertificate.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Exports an X509Certificate2 to PFX or PEM(+key).
 4    .DESCRIPTION
 5        This function exports a given X509Certificate2 object to a specified file path in either PFX or PEM format.
 6        If the PEM format is chosen and the IncludePrivateKey switch is set, it will also export the private key.
 7    .PARAMETER Certificate
 8        The X509Certificate2 object to export.
 9    .PARAMETER FilePath
 10        The file path to export the certificate to (without extension).
 11    .PARAMETER Format
 12        The export format (Pfx or Pem).
 13    .PARAMETER Password
 14        The password to protect the exported PFX file (if applicable).
 15    .PARAMETER IncludePrivateKey
 16        Whether to include the private key in the export (only applicable for PEM format).
 17
 18    .EXAMPLE
 19        Export-KrCertificate -Certificate $cert -FilePath 'C:\certs\my' `
 20            -Format Pem -Password 'p@ss' -IncludePrivateKey
 21    .NOTES
 22        This function requires the Kestrun module to be imported.
 23#>
 24function Export-KrCertificate {
 25    [KestrunRuntimeApi('Everywhere')]
 26    [CmdletBinding()]
 27    param(
 28        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
 29        [System.Security.Cryptography.X509Certificates.X509Certificate2]$Certificate,
 30
 31        [Parameter(Mandatory = $true)]
 32        [string]$FilePath,
 33
 34        [Parameter()]
 35        [ValidateSet('Pfx', 'Pem')]
 36        [string]$Format = 'Pfx',
 37
 38        [Parameter()]
 39        [securestring]$Password,
 40
 41        [Parameter()]
 42        [switch]$IncludePrivateKey
 43    )
 44    process {
 045        if ($null -eq $Certificate) {
 046            throw 'Certificate parameter is required.'
 47        }
 048        if ([string]::IsNullOrWhiteSpace($FilePath)) {
 049            throw 'FilePath parameter is required.'
 50        }
 051        $resolvedPath = Resolve-KrPath -Path $FilePath -KestrunRoot
 052        Write-KrLog -Level Verbose -Message "Resolved file path: $resolvedPath"
 53
 054        $fmtEnum = [Kestrun.Certificates.ExportFormat]::$Format
 055        [Kestrun.Certificates.CertificateManager]::Export($Certificate, $resolvedPath, $fmtEnum, $Password,
 56            $IncludePrivateKey.IsPresent)
 057        Write-KrLog -Level Verbose -Message "Certificate exported to $resolvedPath with format $Format"
 58    }
 59}

Methods/Properties

Export-KrCertificate()