Reputation: 1678
I am following this article https://blogs.msdn.microsoft.com/azuresqldbsupport/2017/09/01/how-to-create-an-azure-ad-application-in-powershell/
to create Azure Active Directory Application
using PowerShell
but it fails because identifierUris
already exists.
$appName = "yourappname123"
$uri = "http://yourappname123"
$secret = "yoursecret123"
$azureAdApplication = New-AzADApplication -DisplayName $appName -HomePage $Uri -IdentifierUris $Uri -Password $(ConvertTo-SecureString -String $secret -AsPlainText -Force)
Is it possible to delete identifier before creating application or a validation check whether identifierUri exists before creating application
Upvotes: 0
Views: 1124
Reputation: 61068
You can use Get-AzADApplication with parameter -IdentifierUri
to test if there already is an app with that IdentifierUri:
$appName = "yourappname123"
$uri = "http://yourappname123"
$secret = "yoursecret123"
$password = ConvertTo-SecureString -String $secret -AsPlainText -Force
# test if an app using that uri is already present
$app = (Get-AzADApplication -IdentifierUri $uri)
if ($app) {
Write-Warning "An app with identifier uri '$uri' already exists: '$($app.DisplayName)'"
# there already is an app that uses this identifier uri..
# decide what to do:
# - choose a new uri for the new app?
# - change the identifier uri on the existing app?
# you can do that using
# $app | Update-AzADApplication -IdentifierUri 'THE NEW URI FOR THIS APP'
}
else {
# all seems clear; create your new app
$azureAdApplication = New-AzADApplication -DisplayName $appName -HomePage $Uri -IdentifierUris $Uri -Password $password
}
Upvotes: 1