Hello John Emanuel
From your description, I understand that you’re experiencing issues while renewing the certificate between NPS server and an Azure Enterprise app using PowerShell.
Below are the steps to Renew the certificate between NPS server and an Azure Enterprise app using PowerShell.
Correctly encode the certificate.
Properly convert it into a KeyCredential object.
Pass it correctly to the Update-MgServicePrincipal command.
Step 1: Read the Certificate as a Byte Array Since you’ve already exported the certificate as a .cer file, let's make sure it's correctly encoded and converted to a Byte[].
Run the following commands:
First, define the certificate path: $certPath = "C:\Program Files\Microsoft\AzureMfa\Config\AzureMFACert.cer"
Read the certificate bytes: $certBytes = [System.IO.File]::ReadAllBytes($certPath)
This converts the certificate to a byte array, which is required for the KeyCredential object.
Step 2: Convert the Certificate into a KeyCredential Object You need to create a KeyCredential object using the Microsoft.Graph.PowerShell.Models.MicrosoftGraphKeyCredential class.
Create the key credential object:
$keyCredential = New-Object Microsoft.Graph.PowerShell.Models.MicrosoftGraphKeyCredential $keyCredential.Type = "AsymmetricX509Cert" $keyCredential.Usage = "Verify" $keyCredential.Key = $certBytes $keyCredential.DisplayName = "Azure MFA Cert"
This ensures that the certificate is being processed as an object and not a string or hashtable.
Step 3: Add the Certificate to the Existing Service Principal Now update the existing service principal with the correct Object ID:
Use the Id from your earlier Get-MgServicePrincipal output (8c5b878b-e177-4645-ba14-f2a3809275da): or <ObjectId>
Update-MgServicePrincipal -ServicePrincipalId "<ObjectId>" -KeyCredentials @($keyCredential) If successful, the command will complete without any output — this is normal behavior for the Update-MgServicePrincipal command.
Step 4: Verify the Certificate Binding Confirm that the certificate is correctly attached to the service principal:
Get-MgServicePrincipal -ServicePrincipalId "<ObjectId>" | Select-Object DisplayName, KeyCredentials You should see the new key listed under KeyCredentials.
Step 5: Restart NPS to Apply the Changes Finally, restart the NPS service:
Restart-Service -Name "NPS"
https://learn.microsoft.com/en-us/entra/identity/authentication/howto-mfa-nps-extension-rdg
after performing the above steps, you are able to see the certificate was Current with expiry date in azure portal.
I hope this information is helpful. Please feel free to reach out if you have any further questions.
If the answer is helpful, please click "Accept Answer" and kindly "upvote it". If you have extra questions about this answer, please click "Comment"