Diwakar Reddy
Diwakar Reddy

Reputation: 146

How to add individual Owners to AAD app register using AZ module powershell script

Unable to add owners into AAD app register using Az module powershell script Using Below Script to add users on app.

$appName = "Sampleapp"
$ownerEmail = "[email protected]"

$app = Get-AzADApplication -DisplayName $appName
if ($app) {
    $owner = Get-AzADUser -UserPrincipalName $ownerEmail
    if ($owner) {
        Add-AzADAppOwner -ApplicationId $app.ApplicationId -OwnerObjectId $owner.Id
        Write-Host "Owner added successfully."
    } else {
        Write-Host "Owner with email $ownerEmail not found."
    }
} else {
    Write-Host "Application with name $appName not found."
}

Getting below error ** The term 'Add-AzADAppOwner' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was | included, verify that the path is correct and try again. **

Unable to find the AZ command to add individual users in app register

enter image description here

Upvotes: 0

Views: 310

Answers (1)

Rukmini
Rukmini

Reputation: 15464

Initially I got the same error as below:

$appName = "Sampleapp"
$ownerEmail = "[email protected]"

$app = Get-AzADApplication -DisplayName $appName
if ($app) {
    $owner = Get-AzADUser -UserPrincipalName $ownerEmail
    if ($owner) {
        Add-AzADAppOwner -ApplicationId $app.ApplicationId -OwnerObjectId $owner.Id
        Write-Host "Owner added successfully."
    } else {
        Write-Host "Owner with email $ownerEmail not found."
    }
} else {
    Write-Host "Application with name $appName not found."
}

enter image description here

Note that: There is no direct Az PowerShell command to add owners to the Azure AD application. Refer this GitHub blog

Alternatively, you can make use of either AzureAD or MicrosoftGraph or Az CLI module to add owners to the group.

Connect-AzureAD

$appName = "RukTestApp"
$ownerEmail = "[email protected]"

# Fetch Azure AD application
$app = Get-AzureADApplication -Filter "DisplayName eq '$appName'"

if ($app) {
    # Fetch the owner by email
    $owner = Get-AzureADUser -ObjectId $ownerEmail

    if ($owner) {
        # Add owner to the Azure AD application
        Add-AzureADApplicationOwner -ObjectId $app.ObjectId -RefObjectId $owner.ObjectId
        Write-Host "Owner added successfully."
    } else {
        Write-Host "Owner with email $ownerEmail not found."
    }
} else {
    Write-Host "Application with name $appName not found."
}

enter image description here

Owner added successfully to the Microsoft Entra application:

enter image description here

Reference:

Get Azure AD Application Owner (Get-AzADApplicationOwner) · Issue #1339 · MicrosoftDocs/feedback · GitHub

Upvotes: 1

Related Questions