upload certificate app registration using powershell

Copper Contributor

Hi,

 

I am trying to upload certificate to Azure AD app using powershell, any leads please help.

1 Reply

@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