< 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@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
0%
Covered lines: 0
Uncovered lines: 9
Coverable lines: 9
Total lines: 52
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 09/07/2025 - 18:41:40 Line coverage: 0% (0/4) Total lines: 44 Tag: Kestrun/Kestrun@2192d4ccb46312ce89b7f7fda1aa8c915bfa228409/09/2025 - 05:44:24 Line coverage: 0% (0/9) Total lines: 53 Tag: Kestrun/Kestrun@a26a91936c400a7f2324671b2222643fb772438111/19/2025 - 02:25:56 Line coverage: 0% (0/9) Total lines: 52 Tag: Kestrun/Kestrun@98ff905e5605a920343154665980a71211a03c6d

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        [Parameter(Mandatory = $true)]
 31        [string]$FilePath,
 32        [ValidateSet('Pfx', 'Pem')]
 33        [string] $Format = 'Pfx',
 34        [securestring] $Password,
 35        [switch] $IncludePrivateKey
 36    )
 37    process {
 038        if ($null -eq $Certificate) {
 039            throw "Certificate parameter is required."
 40        }
 041        if ([string]::IsNullOrWhiteSpace($FilePath)) {
 042            throw "FilePath parameter is required."
 43        }
 044        $resolvedPath = Resolve-KrPath -Path $FilePath -KestrunRoot
 045        Write-KrLog -Level Verbose -Message "Resolved file path: $resolvedPath"
 46
 047        $fmtEnum = [Kestrun.Certificates.ExportFormat]::$Format
 048        [Kestrun.Certificates.CertificateManager]::Export($Certificate, $resolvedPath, $fmtEnum, $Password,
 49            $IncludePrivateKey.IsPresent)
 050        Write-KrLog -Level Verbose -Message "Certificate exported to $resolvedPath with format $Format"
 51    }
 52}

Methods/Properties

Export-KrCertificate()