Edit

New-AzRoleAssignment

Create an Azure RBAC role assignment.

Syntax

SubscriptionScope (Default)

New-AzRoleAssignment
    -ObjectId <string>
    -RoleDefinitionId <string>
    [-SubscriptionId <string>]
    [-ObjectType <string>]
    [-Name <string>]
    [-Description <string>]
    [-Condition <string>]
    [-ConditionVersion <string>]
    [-Profile <string>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

ResourceGroup

New-AzRoleAssignment
    -ResourceGroupName <string>
    -ObjectId <string>
    -RoleDefinitionId <string>
    [-SubscriptionId <string>]
    [-ObjectType <string>]
    [-Name <string>]
    [-Description <string>]
    [-Condition <string>]
    [-ConditionVersion <string>]
    [-Profile <string>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Scope

New-AzRoleAssignment
    -Scope <string>
    -ObjectId <string>
    -RoleDefinitionId <string>
    [-ObjectType <string>]
    [-Name <string>]
    [-Description <string>]
    [-Condition <string>]
    [-ConditionVersion <string>]
    [-Profile <string>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Description

Create an Azure role-based access control (RBAC) role assignment, granting the principal given by -ObjectId the role given by -RoleDefinitionId at a scope. The scope defaults to the active subscription and can be narrowed with -ResourceGroupName or overridden with -Scope (the two are mutually exclusive). -ObjectId takes a GUID; -RoleDefinitionId takes a role definition GUID or a fully-qualified role definition ID. Principal name/UPN/service-principal and role-name resolution are not yet supported. The assignment name is generated when -Name is omitted. With a generated name, re-running create for a principal, role, and scope that already has an assignment returns that existing assignment instead of failing. Supplying an explicit -Name is stricter: the command then fails if a differently-named assignment already grants that access.

Examples

Create a role assignment at a resource group scope

Grant the principal the given role over a resource group.

New-AzRoleAssignment -ResourceGroupName my-rg -ObjectId 11111111-2222-3333-4444-555555555555 -RoleDefinitionId b24988ac-6180-42a0-ab88-20f7382dd24c

Create a role assignment with a principal type and description

New-AzRoleAssignment -Scope /subscriptions/00000000-0000-0000-0000-000000000000 -ObjectId 11111111-2222-3333-4444-555555555555 -RoleDefinitionId b24988ac-6180-42a0-ab88-20f7382dd24c -ObjectType ServicePrincipal -Description "grant CI access"

Parameters

-Condition

Condition under which the principal is granted permission.

Parameter properties

Type:String
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ConditionVersion

Version of the condition syntax (currently only '2.0').

Parameter properties

Type:String
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Parameter properties

Type:SwitchParameter
Supports wildcards:False
DontShow:False
Aliases:cf

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Description

Description of the role assignment.

Parameter properties

Type:String
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Name

The role assignment name (a GUID). Generated when omitted.

Parameter properties

Type:String
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ObjectId

The principal's object (principal) ID (GUID) to assign the role to.

Parameter properties

Type:String
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ObjectType

The principal type of the assigned principal (User, Group, ServicePrincipal, or ForeignGroup).

Parameter properties

Type:String
Accepted values:User, Group, ServicePrincipal, ForeignGroup
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Profile

Name of a saved profile to use for this call instead of the currently-active one. Manage profiles with Set-AzProfile / Get-AzProfile.

Parameter properties

Type:String
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ResourceGroupName

Create the role assignment scoped to this resource group under the subscription. Mutually exclusive with -Scope.

Parameter properties

Type:String
Supports wildcards:False
DontShow:False

Parameter sets

ResourceGroup
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-RoleDefinitionId

The role definition ID (GUID) or a fully-qualified role definition ID to assign. Role name resolution is not yet supported.

Parameter properties

Type:String
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Scope

Fully qualified scope to create the role assignment at (the grant target). Mutually exclusive with -ResourceGroupName. Defaults to the subscription scope.

Parameter properties

Type:String
Supports wildcards:False
DontShow:False

Parameter sets

Scope
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-SubscriptionId

Azure Subscription Id. Defaults to the active profile's subscription.

Parameter properties

Type:String
Supports wildcards:False
DontShow:False

Parameter sets

SubscriptionScope
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
ResourceGroup
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-WhatIf

Runs the command in a mode that only reports what would happen without performing the actions.

Parameter properties

Type:SwitchParameter
Supports wildcards:False
DontShow:False
Aliases:wi

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Outputs

Microsoft.Azure.Azclips.Extensions.Resources.Models.RoleAssignment

The created RoleAssignment, including its id, name, and properties (role definition id, principal id and type, and scope).