Reputation: 2148
I am trying to assign a User Assigned Identity to a API Management instance on Azure from Powershell. I have taken reference from below link -
I am trying the same code -
# Get an API Management instance
$apimService = Get-AzApiManagement -ResourceGroupName $resourceGroupName -Name $apiManagementName
# Create a user-assigned identity. This requires installation of the "Az.ManagedServiceIdentity" module.
$userAssignedIdentity = New-AzUserAssignedIdentity -Name $userAssignedIdentityName -ResourceGroupName $resourceGroupName
# Update an API Management instance
$userIdentities = @($userAssignedIdentity.Id)
Set-AzApiManagement -InputObject $apimService -UserAssignedIdentity $userIdentities
but it is always giving me below error message -
Set-AzApiManagement: Operation returned an invalid status code 'BadRequest'
What am I missing? What's wrong with the code? Any immediate help is appreciated!! Thanks in advance.. Am using Powershell..
Edit
The API Management instance is already having one User Assigned Identity, I am trying to add another..
Upvotes: 0
Views: 567
Reputation: 23141
Regarding the issue, please refer to the following code
Connect-AzAccount
$userAssignedIdentity = New-AzUserAssignedIdentity -Name "myapi" -ResourceGroupName ""
$userIdentities = @($userAssignedIdentity.Id)
$apimService = Get-AzApiManagement -ResourceGroupName "" -Name "huryApim"
[string[]]$test= $apimService.Identity.UserAssignedIdentity.Keys
[string[]]$test += $userAssignedIdentity.Id
Set-AzApiManagement -InputObject $apimService -UserAssignedIdentity $test
Upvotes: 1