Edit

Share via


Set-AzRoleDefinition

Modifies a custom role in Azure RBAC. Provide the modified role definition either as a JSON file or as a PSRoleDefinition. First, use the Get-AzRoleDefinition command to retrieve the custom role that you wish to modify. Then, modify the properties that you wish to change. Finally, save the role definition using this command.

Syntax

InputFileParameterSet

Set-AzRoleDefinition
    -InputFile <String>
    [-SkipClientSideScopeValidation]
    [-DefaultProfile <IAzureContextContainer>]
    [<CommonParameters>]

RoleDefinitionParameterSet

Set-AzRoleDefinition
    -Role <PSRoleDefinition>
    [-SkipClientSideScopeValidation]
    [-DefaultProfile <IAzureContextContainer>]
    [<CommonParameters>]

Description

The Set-AzRoleDefinition cmdlet updates an existing custom role in Azure Role-Based Access Control. Provide the updated role definition as an input to the command as a JSON file or a PSRoleDefinition object. The role definition for the updated custom role MUST contain the Id and all other required properties of the role even if they are not updated: DisplayName, Description, Actions, AssignableScopes. NotActions, DataActions, NotDataActions are optional.

Examples

Example 1: Update using PSRoleDefinitionObject

$roleDef = Get-AzRoleDefinition "Contoso On-Call"
$roleDef.Actions.Add("Microsoft.ClassicCompute/virtualmachines/start/action")
$roleDef.Description = "Can monitor all resources and start and restart virtual machines"
$roleDef.AssignableScopes = @("/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
Set-AzRoleDefinition -Role $roleDef

Example 2: Create using JSON file

Set-AzRoleDefinition -InputFile C:\Temp\roleDefinition.json
<#
Following is a sample updated role definition json for Set-AzRoleDefinition:
{
        "Id": "52a6cc13-ff92-47a8-a39b-2a8205c3087e",
        "Name": "Updated Role",
        "Description": "Can monitor all resources and start and restart virtual machines",
        "Actions":
        [
            "*/read",
            "Microsoft.ClassicCompute/virtualmachines/restart/action",
            "Microsoft.ClassicCompute/virtualmachines/start/action"
        ],
        "NotActions":
        [
            "*/write"
        ],
        "DataActions":
        [
            "Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read"
        ],
        "NotDataActions":
        [
            "Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write"
        ],
        "AssignableScopes": ["/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"]
}
#>

Parameters

-DefaultProfile

The credentials, account, tenant, and subscription used for communication with azure

Parameter properties

Type:IAzureContextContainer
Default value:None
Supports wildcards:False
DontShow:False
Aliases:AzContext, AzureRmContext, AzureCredential

Parameter sets

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

-InputFile

File name containing a single json role definition to be updated. Only include the properties that are to be updated in the JSON. Id property is Required.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

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

-Role

Role definition object to be updated

Parameter properties

Type:PSRoleDefinition
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

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

-SkipClientSideScopeValidation

If specified, skip client side scope validation.

Parameter properties

Type:SwitchParameter
Default value:None
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

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.

Inputs

PSRoleDefinition

Outputs

PSRoleDefinition

Notes

Keywords: azure, azurerm, arm, resource, management, manager, resource, group, template, deployment