# Replace these variables with your own values
$vaultName = "<key vault
name>"
$certificateName =
"<certificate name>"
$pfxPath = "<folder
path>\<certname>.pfx"
$password = "<exportpassword>"
$cert = Get-AzKeyVaultCertificate
-VaultName $vaultName -Name $certificateName
$pfxSecret =
Get-AzKeyVaultSecret -VaultName $vaultName -Name $cert.Name -AsPlainText
$pfxUnprotectedBytes
= [Convert]::FromBase64String($pfxSecret)
$pfx
= New-Object Security.Cryptography.X509Certificates.X509Certificate2Collection
$pfx.Import($pfxUnprotectedBytes,
$null,
[Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
$pfxProtectedBytes
= $pfx.Export([Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12,
$password)
[IO.File]::WriteAllBytes($pfxPath,
$pfxProtectedBytes)