Create a custom RBAC (role-based access control) role using PowerShell in Azure

%3CLINGO-SUB%20id%3D%22lingo-sub-1771298%22%20slang%3D%22en-US%22%3ECreate%20a%20custom%20RBAC%20(role-based%20access%20control)%20role%20using%20PowerShell%20in%20Azure%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1771298%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Azure%20friends%2C%3C%2FP%3E%3CP%3EI%20used%20the%20PowerShell%20ISE%20for%20this%20configuration.%20But%20you%20are%20also%20very%20welcome%20to%20use%20Visual%20Studio%20Code%2C%20just%20as%20you%20wish.%26nbsp%3BPlease%20start%20with%20the%20following%20steps%20to%20begin%20the%20deployment%20(the%20Hashtags%20are%20comments)%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23The%20first%20two%20lines%20have%20nothing%20to%20do%20with%20the%20configuration%2C%20but%20make%20some%20space%20below%20in%20the%20blue%20part%20of%20the%20ISE%3C%2FP%3E%3CP%3E%3CSTRONG%3ESet-Location%20C%3A%5CTemp%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3EClear-Host%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23So%20that%20you%20can%20carry%20out%20the%20configuration%2C%20you%20need%20the%20necessary%20cmdlets%2C%20these%20are%20contained%20in%20the%20module%20Az%20(is%20the%20higher-level%20module%20from%20a%20number%20of%20submodules)%3C%2FP%3E%3CP%3E%3CSTRONG%3EInstall-Module%20-Name%20Az%20-Force%20-AllowClobber%20-Verbose%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23Log%20into%20Azure%3CBR%20%2F%3E%3CSTRONG%3EConnect-AzAccount%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23We%20look%20at%20the%20provider%3C%2FP%3E%3CP%3E%3CSTRONG%3EGet-AzProviderOperation%20%22Microsoft.Support%2F*%22%20%7C%20FT%20Operation%2C%20Description%20-AutoSize%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23We%20copy%20an%20existing%20role%20and%20expand%20it%20later%3C%2FP%3E%3CP%3E%3CSTRONG%3EGet-AzRoleDefinition%20-Name%20%22Reader%22%20%7C%20ConvertTo-Json%20%7C%20Out-File%20C%3A%5CTemp%5CReaderSupportRole.json%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23Open%20the%20ReaderSupportRole.json%20in%20VSCode%20or%20any%20other%20editor%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23We%20need%20the%20subscription%20ID%3C%2FP%3E%3CP%3E%3CSTRONG%3EGet-AzSubscription%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23In%20AssignableScopes%2C%20add%20your%20subscription%20ID%3CBR%20%2F%3E%23Change%20the%20Name%20and%20Description%20properties%20to%20%22Reader%20Support%20Tickets%22%20and%20%22View%20everything%20in%20%23the%20subscription%20and%20also%20open%20support%20tickets.%22%20Also%20change%20from%20%22%3CSPAN%3EIsCustom%22%3C%2FSPAN%3E%3CSPAN%3E%3A%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3Efalse%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%22%20to%20%3C%2FSPAN%3E%3CSPAN%3E%23%22IsCustom%22%3C%2FSPAN%3E%3CSPAN%3E%3A%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%3CSPAN%3Etrue.%20In%20%22Actions%22%20add%20%3C%2FSPAN%3E%3C%2FSPAN%3E%22Microsoft.Support%2F*%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3ENew-AzRoleDefinition%20-InputFile%20%22C%3A%5CTemp%5CReaderSupportRole.json%22%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23To%20list%20all%20your%20custom%20roles%3CBR%20%2F%3E%3CSTRONG%3EGet-AzRoleDefinition%20%7C%20%3F%20%7B%24_.IsCustom%20-eq%20%24true%7D%20%7C%20FT%20Name%2C%20IsCustom%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Eor%3C%2FP%3E%3CP%3E%3CSTRONG%3EGet-AzRoleDefinition%20%22Reader%20Support%20Tickets%22%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20also%20see%20the%20custom%20role%20in%20the%20Azure%20portal.%26nbsp%3BNow%20you%20have%20configured%20an%20RBAC%20role%20with%20the%20PowerShell%20in%20Azure!%20Congratulations!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20hope%20this%20article%20was%20useful.%20Best%20regards%2C%20Tom%20Wechsler%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EP.S.%26nbsp%3BAll%20scripts%20(%23PowerShell%2C%20Azure%20CLI%2C%20%23Terraform%2C%20%23ARM)%20that%20I%20use%20can%20be%20found%20on%20github!%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Ftomwechsler%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Ftomwechsler%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1771298%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EHands-on-Labs%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EIdentity%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
MVP

 

Hi Azure friends,

I used the PowerShell ISE for this configuration. But you are also very welcome to use Visual Studio Code, just as you wish. Please start with the following steps to begin the deployment (the Hashtags are comments):

 

#The first two lines have nothing to do with the configuration, but make some space below in the blue part of the ISE

Set-Location C:\Temp
Clear-Host

 

#So that you can carry out the configuration, you need the necessary cmdlets, these are contained in the module Az (is the higher-level module from a number of submodules)

Install-Module -Name Az -Force -AllowClobber -Verbose

 

#Log into Azure
Connect-AzAccount

 

#We look at the provider

Get-AzProviderOperation "Microsoft.Support/*" | FT Operation, Description -AutoSize

 

#We copy an existing role and expand it later

Get-AzRoleDefinition -Name "Reader" | ConvertTo-Json | Out-File C:\Temp\ReaderSupportRole.json

 

#Open the ReaderSupportRole.json in VSCode or any other editor

 

#We need the subscription ID

Get-AzSubscription

 

#In AssignableScopes, add your subscription ID
#Change the Name and Description properties to "Reader Support Tickets" and "View everything in the subscription and also open support tickets." Also change from "IsCustom":  false " to "IsCustom":  true. In "Actions" add "Microsoft.Support/*"

 

#Now we add our role to Azure

New-AzRoleDefinition -InputFile "C:\Temp\ReaderSupportRole.json"

 

#To list all your custom roles
Get-AzRoleDefinition | ? {$_.IsCustom -eq $true} | FT Name, IsCustom

or

Get-AzRoleDefinition "Reader Support Tickets"

 

You can also see the custom role in the Azure portal. Now you have configured an RBAC role with the PowerShell in Azure! Congratulations!

 

I hope this article was useful. Best regards, Tom Wechsler

 

P.S. All scripts (#PowerShell, Azure CLI, #Terraform, #ARM) that I use can be found on github! https://github.com/tomwechsler

0 Replies