Skip to content

Instantly share code, notes, and snippets.

@FH-Inway
Last active December 22, 2023 14:45
Show Gist options
  • Save FH-Inway/86507ac3ed3e9b2e645ca015b9634f9a to your computer and use it in GitHub Desktop.
Save FH-Inway/86507ac3ed3e9b2e645ca015b9634f9a to your computer and use it in GitHub Desktop.
# Downloads a certificate from an Azure key vault and stores it as .pfx and .cer file in C:\Temp\Certificate
# The files can then be used to enable the Entra integration for a Dynamics 365 Finance and Operations cloud hosted environment.
# See https://github.com/d365collaborative/d365fo.tools/issues/789 for more information
# Original file: https://gist.github.com/FH-Inway/86507ac3ed3e9b2e645ca015b9634f9a
$vaultName = 'MyKeyVaultname'
$certificateName = 'MyCertificateName'
$null = Connect-AzAccount -Tenant 00000000-0000-0000-0000-000000000000 -Subscription 00000000-0000-0000-0000-000000000000
$pfxSecret = Get-AzKeyVaultSecret -VaultName $vaultName -Name $certificateName -AsPlainText
$secretByte = [Convert]::FromBase64String($pfxSecret)
if (!(Test-Path -Path "C:\Temp\Certificate")) {
$null = New-Item -Path "C:\Temp\Certificate" -ItemType Directory
}
Set-Content -Path "C:\Temp\Certificate\$certificateName.pfx" -Value $secretByte -Encoding Byte
Get-PfxCertificate -FilePath "C:\Temp\Certificate\$certificateName.pfx" | Export-Certificate -FilePath "C:\Temp\Certificate\$certificateName.cer" -Type CERT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment