New-AzRoleAssignment

In this Azure PowerShell article, we will discuss the syntax and usage of the New-AzRoleAssignment Azure PowerShell cmdlet with examples.

New-AzRoleAssignment

New-AzRoleAssignment is a very good PowerShell command that you can use to assign an RBAC role to a specific principal for a specified scope. Let’s discuss the Syntax of the New-AzRoleAssignment Azure PowerShell cmdlet.

Syntax

Below is the syntax of the New-AzRoleAssignment PowerShell command.

New-AzRoleAssignment
   -ObjectId <String>

   -RoleDefinitionName <String>
[-Scope <String>]
New-AzRoleAssignment
   -ObjectId <String>

 -RoleDefinitionName <String>
  -ResourceGroupName <String>
  
New-AzRoleAssignment
   -SignInName <String>
-RoleDefinitionName <String>
 -ResourceName <String>
-ResourceType <String>
-ResourceGroupName <String>

 

Now, let’s discuss some examples of how to use the New-AzRoleAssignment PowerShell command.

Example-1:

You can execute the below Azure PowerShell command to grant a contributor role to the user “User2@tsinfotechnologies.onmicrosoft.com” under the resource group “MyNewResGrp” scope, and the role assignment is available for delegation.

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

Example-2:

Below Azure PowerShell cmdlet can help you to grant owner access to the user “User2@tsinfotechnologies.onmicrosoft.com” to the “TsInfoweb” website.

New-AzRoleAssignment -SignInName User2@tsinfotechnologies.onmicrosoft.com -RoleDefinitionName Owner -Scope "/subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/resourcegroups/MyNewResGrp/providers/Microsoft.Web/sites/TsInfoweb"

You may also like following the articles below

Wrapping Up

In this Azure PowerShell article, we discussed the syntax and usage of the New-AzRoleAssignment Azure PowerShell cmdlet with examples. Thanks for reading this article !!!