Forum Discussion
upload certificate app registration using powershell
Hi,
I am trying to upload certificate to Azure AD app using powershell, any leads please help.
- AngrydotCopper Contributor
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