In addition, if you look at the Roles tab you can see custom role there as well.
Awesome! The custom role that has been registered in Azure and we can go ahead and make use of the role.
Deleting a Custom Role
In case if, you want to go ahead and delete that role, first delete the role assignment then after deleting the custom role. Otherwise, you will get an error as shown below
Remove-AzRoleDefinition: There are existing role assignments referencing role c5104a7d-4fcd-4eff-a2a3-8e883619417b. The role assignments must be deleted before the role can be deleted.
To remove role assignment, we can run the below command first. This command similar to a new role assignment. The following example removes My Custom Role assignment from the
[email protected] user on the cloud-shell-storage-westeurope resource group.
- Remove-AzRoleAssignment -ResourceGroupName cloud-shell-storage-westeurope -SignInName [email protected] -RoleDefinitionName "My Custom Role"
To delete a custom role, use the Remove-AzRoleDefinition command.
- Get-AzRoleDefinition "My Custom Role" | Remove-AzRoleDefinition
You can easily achieve the same functionality through the Azure portal as well. For that, we need to delete the role assignment first then from the roles tab, select custom role, and then click on remove.
Conclusion
In this article, we have seen how we can create a custom role from Azure PowerShell and how newly created roles assigned to a user, and finally, we deleted that custom role. Hope you gained some insights into this topic and found this information useful!