简体   繁体   中英

How to remove identifierUris using PowerShell in Azure Active Directory Application

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

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM