#30 Create Azure AD apps with one line of code

If you’ve ever built an app connected to Microsoft 365, this will sound familiar.

You work on your app with other devs on your team. You store the code centrally in source control, so that you can work independently, but can also integrate each other’s work and test if it works as intended. When you all started working on the project, you had to start with creating an Azure AD app in your dev tenant. Someone created a Word doc with the necessary settings.

As you’re working on your app, you had to change a thing or two in the Azure AD app. Have you updated the doc? You’d better because soon the app will be deployed to the customer and they will need to create the Azure AD app too.

Many devs building apps for Microsoft 365 go through this regularly. Some choose to automate creating Azure AD apps using the Azure CLI and end up with scripts like:

$appName = "My AAD app"

"Creating AAD app $appName..."
$app = az ad app create --display-name $appName --required-resource-accesses @app-manifest.json | ConvertFrom-Json

# wait for the AAD app to be created or the script will fail later on
"Waiting for the app to be fully provisioned..."
Start-Sleep -Seconds 10

# add current user as app owner
"Adding current user as app owner..."
$userId = az ad signed-in-user show --query objectId -o tsv
az ad app owner add --id $app.appId --owner-object-id $userId

$appSecret = az ad app credential reset --id $app.appId --credential-description "Default" | ConvertFrom-Json


Since creating Azure AD apps is such a fundamental step in building apps on Microsoft 365, recently the CLI for Microsoft 365 team set out to simplify creating Azure AD apps. We managed to bring down the above script to just one line of code:

m365 aad app add --name 'My AAD app' --withSecret --apisApplication 'https://graph.microsoft.com/Group.ReadWrite.All,https://graph.microsoft.com/Directory.Read.All'

Don’t you think it’s not just shorter but more readable as well?

If you build apps for Microsoft 365, we’d love you to give the new aad app add command a try and tell us what you think. Is everything clear? Can we simplify something? Do we miss anything?

Looking forward to hearing from you

Others found also helpful: