ps/Modules/Alkami.DevOps.Certificates/Private/Get-CertificateExportInfo.ps1

37 lines
1.3 KiB
PowerShell
Raw Permalink Normal View History

2023-05-30 22:51:22 -07:00
function Get-CertificateExportInfo {
<#
.SYNOPSIS
Fetches a Certificate's Export Information.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[System.Security.Cryptography.X509Certificates.X509Certificate2]$Cert,
[Parameter(Mandatory = $true)]
[string]$ExportCertPath)
$exportInfo = [PSCustomObject]@{
CertExportType = [System.Security.Cryptography.X509Certificates.X509ContentType]::Pfx
ExportCertFile = Join-Path $exportCertPath "$certName.pfx"
ExportCertPath = $exportCertPath
CertPassword = ""
ADGroups = ""
CertName = ""
ExpirationDate = $cert.NotAfter
Thumbprint = $cert.Thumbprint
}
if ($cert.HasPrivateKey) {
if (!$cert.PrivateKey.CspKeyContainerInfo.Exportable) {
Write-Warning "Certificate $certName with thumbprint $($cert.Thumbprint) has a private key but is marked as unexportable.
This certificate will not be exported"
$exportInfo.certExportType = [System.Security.Cryptography.X509Certificates.X509ContentType]::Unknown
}
}
else {
$exportInfo.certExportType = [System.Security.Cryptography.X509Certificates.X509ContentType]::Cert
$exportInfo.exportCertFile = Join-Path $exportCertPath "$certName.cer"
}
return $exportInfo
}