I am using Powershell to add roles to an existing App Registration in Azure. I am using this command:
Set-AzureADApplication -ObjectId $myApp.ObjectId -AppRoles $newAppRoles
$newAppROles
is an array of Microsoft.Open.AzureAD.Model.AppRole
When I execute the above command I get this error:
Set-AzureADApplication : Cannot convert 'System.Collections.Generic.List`1[Microsoft.Open.AzureAD.Model.AppRole]' to the type 'Microsoft.Open.AzureAD.Model.AppRole' required by parameter 'AppRoles'. Specified method is not supported.
The documentation for SetAzureADApplication
says that it requires a list of the app roles; but I am getting this error. There seems to be no other documentation to help me out. Can someone tell me what I am doing wrong.
Below is the full code
Connect-AzureAD
$myApp = ""
$appName = "Narasimham POC Powershell - Multiple reply URLs"
if (!($myApp = Get-AzureADApplication -Filter "DisplayName eq '$($appName)'" -ErrorAction SilentlyContinue)) {
Write-Output "Application $appName not found"
}
else {
Write-Output $myApp
$currentAppRoles = $myApp.AppRoles
$appRole = New-Object -TypeName Microsoft.Open.AzureAD.Model.AppRole
$appRole.IsEnabled = $true
$appRole.DisplayName = "Read Role"
$appRole.Value = "Reader"
$appRole.AllowedMemberTypes = "User"
$appRole.Id = New-Guid
$appRole.Description = "Reader Role for Narasimham POC Powershell"
$newAppRoles = @($currentAppRoles, $appRole)
Write-Output $newAppRoles
Set-AzureADApplication -ObjectId $myApp.ObjectId -AppRoles $newAppRoles
}