Feb 16 2022 12:20 AM
Hi,
I am trying to upload certificate to Azure AD app using powershell, any leads please help.
Feb 15 2023 12:40 PM - last edited on Nov 09 2023 02:07 AM by merillms
@harshahz The snippet below for pfx certs:
$certificateAuthPassword = "Password123!"
$appRegistrationObjectID = "<insert App Registration Object ID here>"
$certFile = "C:\certs\my-self-signed-cert.pfx"
$pwdCertAuth = ConvertTo-SecureString -String $certificateAuthPassword -Force -AsPlainText
$certA = New-Object System.Security.Cryptography.X509Certificates.X509Certificate($certFile, $pwdCertAuth)
$keyValue = [System.Convert]::ToBase64String($certA.GetRawCertData())
$connectedTenant = Connect-AzureAD # this is an interactive login
Write-Host "Connected to $($connectedTenant.TenantDomain)" -ForegroundColor Green # to verify connected
$application = Get-AzureADApplication -ObjectId $appRegistrationObjectID
Write-Host "App Registration is [$($application.DisplayName)]" -ForegroundColor Green # to verify got the correct App Registration
New-AzureADApplicationKeyCredential -ObjectId $application.ObjectId -Type AsymmetricX509Cert -Usage Verify -Value $keyValue | Out-Null
Write-Host "Auth certificate uploaded to [$($application.DisplayName)]" -ForegroundColor Green # to verify success
Disconnect-AzureAD