Reputation: 146
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
Upvotes: 0
Views: 310
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."
}
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."
}
Owner added successfully to the Microsoft Entra application:
Reference:
Upvotes: 1