news and know-how about microsoft, technology, cloud and more.

Update a SPN in AAD with the Azure PowerShell Az module

Yesterday, I wrote how to Update your Azure CLI with Choco. Today, I needed to renew an existing Service Principal Name in an AAD. A SPN stands for Service Principal Name which is used for automation authentication. The PowerShell az module got some updates (v1.0.0). So, hereĀ“s the full step-by-step instruction for renewing a SPN with az ad sp credential.

This updates the steps described at How to create or renew Service Principal Names in Azure Active Directory... Winking smile

az login

rem As a quick reminder, if you have multiple Azure subscriptions, get them and then select one...
az account list --all --out jsonc > C:\temp\mysubscriptions.txt
az account set --subscription "[subscriptionname]"

rem Get a list of all SPNs and write it to a file for easy handling...
az ad sp list > c:\temp\myspns.txt

rem Search for your desired [SPN-ID]...
az ad sp show --id "[SPN-ID]"
az ad sp credential list --id "[SPN-ID]"
az ad sp credential reset --name "[SPN-ID]" --years 2

You get a result like this:

   "appId": "[SPN-ID]",
   "name": "[SPN-ID]",
   "password": "[Some-new-password]",
   "tenant": "[Tenant-ID]"

Renew the new password in your existing or new apps.

Hope these quick steps help!