New-azroleassignment : ‘principalid’ cannot be null.

Recently, I was working with the New-AzRoleAssignment PowerShell command, After executing this command, I got this error New-azroleassignment : ‘principalid’ cannot be null.

New-azroleassignment : ‘principalid’ cannot be null.

For one of the requirements, I have executed the PowerShell script below.

New-AzRoleAssignment  -SignInName User2@tsinfotechnologies.onmicrosoft.com 
-ResourceGroupName MyNewResGrp -RoleDefinitionName Contributor -AllowDelegation

Immediately after executing the above script, I got this error, as shown in the below screenshot for your reference.

New-azroleassignment : 'principalid' cannot be null.

Solution

When I tried solving this error, I noticed that the SignInName “User2@tsinfotechnologies.onmicrosoft.com” doesn’t exist for me, so I got this error when I used another user that exists; I got the expected output as shown in the screenshot below. So, the main point here is to ensure that the user principal name you are using exists.

Now, I executed the same PowerShell script with the new user.

New-AzRoleAssignment  -SignInName tsinfouser@fewlines4bijuhotmail.onmicrosoft.com -ResourceGroupName MyNewResGrp -RoleDefinitionName Contributor -AllowDelegation

After executing the above script, I got the expected output successfully, as shown below.

new-azroleassignment 'principalid' cannot be null.

You may also like the following articles below

Azure Virtual Machine

DOWNLOAD FREE AZURE VIRTUAL MACHINE PDF

Download our free 25+ page Azure Virtual Machine guide and master cloud deployment today!