Helpers/Export-Cert.ps1

1
2
3
4
5
6
7
8
9
10
11
12

$cert = Get-ChildItem Cert:\CurrentUser\My | where friendlyname -eq 'PowershellCMS'

# Password to protect the exported certificate that includes a Private Key
$mypwd = ConvertTo-SecureString -String 'MySecretString' -Force â€“AsPlainText

# Export certificate with private key and all other properties
Export-PfxCertificate -Cert $cert -FilePath c:\mypfx.pfx -Password $mypwd -Force

# This example imports the PFX file my.pfx into the My store for the current user with private key exportable.
Import-PfxCertificate â€“FilePath C:\mypfx.pfx cert:\curentuser\my -Password $mypwd -Exportable