How to register an App in Azure AD by using PowerShell

Recently I came across a situation where I was supposed to register an App in Azure Ad for multiple Environments, I felt it to be very cumbersome to do it using Azure UI interface so I thought to create a scripts for it.

# first install Azure Ad module in PowerShell
Install-module AzureAD

#Store the credential and use these credentials to connect to Azure AD.
$Credentials = Get-Credential
Connect-AzureAD -Credential $Credentials

# Provide Name to the App Name for example PowerBI app
$appName = "PowerBI App "

# Provide the App URI for App. This would be the App home Page. examples could be #"http://localhost:4200" or https://MyPowerbiReports/
$appURI ="http://localhost:4200"

# Now check if App with this name already created ? If it is not created then create it otherwise do not create it.
if(!($myApp = Get-AzureADApplication -Filter "DisplayName eq '$($appName)'" -ErrorAction SilentlyContinue))
$myApp = New-AzureADApplication -DisplayName $appName -IdentifierUris $appURI

# Get the App details
$appName = "PowerBI App"
Get-AzureADApplication  -All $true | ? { $_.DisplayName -match $appName }

#Please store these details in safe place because you may use it for further programming.

I hope this script was helpful.

1 Comment

Leave a Reply