New-AzureRmRoleAssignment "object reference not set to an instance of an object"
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
@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?
@shuagarw can you take a look?
@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.
Hi Mark, yes Get-AzureRMADServicePrincipal returns the principal successfully. Specifying the "scope" parameter does not make a difference.
@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?
@darshanhs90 would you mind taking a look at this?
@alpinemountain Can you repro the same using the new azure powershell release? Since a bunch of issues were resolved
Closing the issue due to no response about the repro