azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

New-AzureRmRoleAssignment "object reference not set to an instance of an object"

Open alpinemountain opened this issue 10 years ago • 8 comments

cmdlet: New-AzureRmRoleAssignment

Prerequisites

#1. Create a new Azure AD directory #2. Create a new user in the directory #3. Use the credentials from (2) when the login box appears below

Login-AzureRmAccount

$certSubject = "https://myuniquewebappname887788" $cert = New-SelfSignedCertificate -CertStoreLocation "cert:\CurrentUser\My" -Subject $certSubject -KeySpec KeyExchange -FriendlyName $certSubject -NotAfter (Get-Date).AddMonths(120) $keyValue = [System.Convert]::ToBase64String($cert.GetRawCertData()) $adAppName = $certSubject $adAppDisplayName = $certSubject $azureAdApplication = New-AzureRmADApplication -DisplayName $adAppDisplayName -HomePage $adAppName -IdentifierUris $adAppName -CertValue $keyValue -EndDate $cert.NotAfter -StartDate $cert.NotBefore New-AzureRmADServicePrincipal -ApplicationId $azureAdApplication.ApplicationId

"Sleeping for 60 seconds so new service principal can propagate..."

Start-Sleep -Seconds 60

Bug: the following cmdlet results in "Object reference not set to an instance of an object":

New-AzureRmRoleAssignment -RoleDefinitionName "Contributor" -ServicePrincipalName $azureAdApplication.ApplicationId.Guid

alpinemountain avatar Oct 11 '16 20:10 alpinemountain

@mattmcloughlin Can you retrieve the service principal using Get-AzureRMADServicePrincipal outside this cmdlet? Also, does it make a difference if you specify the Scope parameter?

markcowl avatar Oct 12 '16 18:10 markcowl

@shuagarw can you take a look?

markcowl avatar Oct 12 '16 18:10 markcowl

@rbacAsk for FYI @mattmcloughlin Do you have an active subscription associated with this ActiveDirectory? Because you need to have a subscription (or below) scope to give access on. Get-AzureRmSubscription cmdlet should tell you that. Regardless, the error thrown by the cmdlet is bad (should convey the reason properly), and I have create a task item on our side to fix it.

shuagarw avatar Oct 12 '16 18:10 shuagarw

Hi Mark, yes Get-AzureRMADServicePrincipal returns the principal successfully. Specifying the "scope" parameter does not make a difference.

alpinemountain avatar Oct 12 '16 18:10 alpinemountain

@shuagarw: "Do you have an active subscription associated with this ActiveDirectory?"

The Directory was created from the portal. How would I associate a Subscription with the Directory?

alpinemountain avatar Oct 12 '16 19:10 alpinemountain

@darshanhs90 would you mind taking a look at this?

cormacpayne avatar Mar 27 '18 22:03 cormacpayne

@alpinemountain Can you repro the same using the new azure powershell release? Since a bunch of issues were resolved

darshanhs90 avatar Mar 27 '18 22:03 darshanhs90

Closing the issue due to no response about the repro

darshanhs90 avatar Jun 29 '18 22:06 darshanhs90