PowerShell Basics: Query Azure Role Based Access Control Assignments

Published Sep 09 2021 02:57 AM 2,514 Views
Microsoft

Title-card.jpg

A great way to learn PowerShell is to set up a scenario in the Azure portal, then try different PowerShell commands to see if you can get the same results. In this article, we'll use Azure Role Based Access control, as it's both visible in the Azure Portal and we have some PowerShell commands for it.

 

The scenario: What Role Based Access Control does somebody have?

 

If you’re taking over an existing Azure environment, or if you organization has been running Azure for a while without enforced consistency of your Role Based Access Control, you might want to explore your existing RBAC assignments at scale or query the permissions for a specific user. RBAC assignments display in the Access control (IAM) blade of Azure resources, resource groups, subscriptions. Because you can assign a role to a user (or group) on an individual resource, their roles and permissions across your Azure environment may vary, and it’s time consuming to check the IAM blade of everything.

 

Fortunately, we can use PowerShell commands and different display formats, to get the data we want. For the purposes of learning PowerShell, you can use the Azure portal to set up RBAC for different test users (and as part of group memberships) on your resources, resource groups and subscription, so you know what results the PowerShell commands should return.

 

To keep things simple, I’m running these commands in Cloud Shell inside the Azure Portal.

 

PowerShell: Get-AzRoleAssignment

Azure RBAC is supported by a number of PowerShell commands, but for this scenario our friend is "Get-AzRoleAssignment".

Looking at the structure of PowerShell, because this is a "Get" command, it's going to query Azure for some information and return the results to us. "AzRoleAssignment" is the base for this command. The command also has a "New-" variation, for adding a new assignment, and a "Remove-" variation for removing a role assignment.

 

Note: If you see older blogs or scripts using "Get-AzureRmRoleAssignment", that was an earlier name for this command before the Az updates. You can often replace the AzureRm bit with just Az, but not in every case as some commands have been deprecated.

 

If you have multiple subscriptions, Cloud Shell will default to one of them, and your commands will query that subscription and it's associated resources. You can run "Get-AzContext" to see which subscription is selected, and run "Set-AzContext -SubscriptionName "My other subscription"" to change to a different one. (Note I've placed the actual name of my other subscription in it's own set of brackets because it has spaces in it).

 

Let's start by just running this command and getting a list of all of the RBAC assignments:

 

 

 

Get-AzRoleAssignment

 

 

 

Next, let's narrow that down so we are only looking for role assignments for one particular user. The Get-AzRoleAssignment command has a range of different parameters we can add which will act as a filter. We'll use SignInName, which you can find in the user's details in Azure Active Directory, if you don't know the exact format (and replace my steve.l example name):

 

 

Get-AzRoleAssignment -SignInName steve.l@scuffinozhotmail.onmicrosoft.com

 

 

This gives us a long list of Steve's role assignments:

The default display for Get-AzRoleAssignment for a single userThe default display for Get-AzRoleAssignment for a single user

 

Now I want to play with the formatting to make it a little more readable onscreen. 

I can format the output of this PowerShell command a few different ways, including as a list or as a table. The output above show sme all of the information that is returned by the query though, so I can use that to further refine the display:

 

 

Get-AzRoleAssignment -SignInName steve.l@scuffinozhotmail.onmicrosoft.com | FL DisplayName, RoleDefinitionName, Scope

 

 

I'm using the 'pipe' character of |  (which is Shift + \ on my keyboard), then the short version of the "format-list" command, then I'm listing just the properties I want to be displayed (DisplayName, RoleDefinitionName and Scope). The pipe tells the first command to send it's output to the second command.

Get-AzRoleAssignment with the output formatted as a listGet-AzRoleAssignment with the output formatted as a list

 

For more formatting command examples, visit Using Format Commands to Change Output View.

 

Hmm, that could still be a pretty long list if Steve had more role assignments. Let's try a table view instead with "format-table" or FT for short:

 

Get-AzRoleAssignment -SignInName steve.l@scuffinozhotmail.onmicrosoft.com | FT DisplayName, RoleDefinitionName, Scope

 

Get-AzRoleAssignment formatted as a tableGet-AzRoleAssignment formatted as a table

 

That's better! So, Steve has a pretty high level of access at the top level of my subscription (Owner) plus a Log Analytics Reader role assignment which isn't needed - I can go and tidy that up. But if I run that same command for a different user, I'm seeing a different scope:

Azure RBAC at the management group levelAzure RBAC at the management group level

Sonia's account is showing the scope as the SCuffSubsMG, not the subscription ID. That's because her Owner access to the current subscription is determined by a role assignment that has been added at the management group level, and as this subscription belongs to that management group, the role assignment is inherited too.

 

There's one more important thing we need to include - what if our user is a member of a group that has been assigned a role? Our commands so far won't include that. We need to add "-ExpandPrincipalGroups". 

Get-AzRoleAssignment -SignInName sarah.g@scuffinozhotmail.onmicrosoft.com -ExpandPrincipalGroups | FL DisplayName, RoleDefinitionName, Scope

Get-AzRoleAssignment with ExpandPrincipalGroups for group membership role assignmentsGet-AzRoleAssignment with ExpandPrincipalGroups for group membership role assignments

Now I can see that as well as being listed as an individual with the Virtual Machine Contributor role to VM CA01, Sarah is also a member of the IT_KeyVaultAdmins group, who have Key Vault Administrator access to the KV-BNE-01 key vault.

 

Azure deny assignments

There's one type of Azure role assignment that won't display with Get-AzRoleAssignment, and that's an Azure deny assignment. You can't manually assign someone a deny assignment - they are created and used by Azure to protect system-managed resources. Azure Blueprints and Azure managed apps are the only way that they can be created.

 

You can query where they are being used in your subscription, by using the Get-AzDenyAssignment command.     

 

Learn more

Now you've learnt about the capabilities and structure of this command, go and explore with different command parameters. If you get stuck, visit List Azure role assignments using PowerShell or Remove Azure role assignments for more inspiration.

 

Get-AzRoleAssignment has the full command syntax, parameters, inputs and outputs.

 

And many of the basic PowerShell concepts we've explored here, like Get/Set/Remove and output formatting, are applicable to a ton of other PowerShell commands too. You're now on your way to understanding and exploring more of PowerShell, especially for scenarios where you can't easily retrieve the same information in the Azure portal.

 

 

 

 

 

 

 

 

 

 

%3CLINGO-SUB%20id%3D%22lingo-sub-2735382%22%20slang%3D%22en-US%22%3EPowerShell%20Basics%3A%20Query%20Azure%20Role%20Based%20Access%20Control%20Assignments%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2735382%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22Title-card.jpg%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F309212i783152ED8CC0C4ED%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Title-card.jpg%22%20alt%3D%22Title-card.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EA%20great%20way%20to%20learn%20PowerShell%20is%20to%20set%20up%20a%20scenario%20in%20the%20Azure%20portal%2C%20then%20try%20different%20PowerShell%20commands%20to%20see%20if%20you%20can%20get%20the%20same%20results.%20In%20this%20article%2C%20we'll%20use%20Azure%20Role%20Based%20Access%20control%2C%20as%20it's%20both%20visible%20in%20the%20Azure%20Portal%20and%20we%20have%20some%20PowerShell%20commands%20for%20it.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--354265146%22%20id%3D%22toc-hId--354261552%22%3EThe%20scenario%3A%20What%20Role%20Based%20Access%20Control%20does%20somebody%20have%3F%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%E2%80%99re%20taking%20over%20an%20existing%20Azure%20environment%2C%20or%20if%20you%20organization%20has%20been%20running%20Azure%20for%20a%20while%20without%20enforced%20consistency%20of%20your%20Role%20Based%20Access%20Control%2C%20you%20might%20want%20to%20explore%20your%20existing%20RBAC%20assignments%20at%20scale%20or%20query%20the%20permissions%20for%20a%20specific%20user.%20RBAC%20assignments%20display%20in%20the%20Access%20control%20(IAM)%20blade%20of%20Azure%20resources%2C%20resource%20groups%2C%20subscriptions.%20Because%20you%20can%20assign%20a%20role%20to%20a%20user%20(or%20group)%20on%20an%20individual%20resource%2C%20their%20roles%20and%20permissions%20across%20your%20Azure%20environment%20may%20vary%2C%20and%20it%E2%80%99s%20time%20consuming%20to%20check%20the%20IAM%20blade%20of%20everything.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFortunately%2C%20we%20can%20use%20PowerShell%20commands%20and%20different%20display%20formats%2C%20to%20get%20the%20data%20we%20want.%20For%20the%20purposes%20of%20learning%20PowerShell%2C%20you%20can%20use%20the%20Azure%20portal%20to%20set%20up%20RBAC%20for%20different%20test%20users%20(and%20as%20part%20of%20group%20memberships)%20on%20your%20resources%2C%20resource%20groups%20and%20subscription%2C%20so%20you%20know%20what%20results%20the%20PowerShell%20commands%20should%20return.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20keep%20things%20simple%2C%20I%E2%80%99m%20running%20these%20commands%20in%20%3CA%20href%3D%22https%3A%2F%2Fshell.azure.com%3Fwt.mc_id%3Dmodinfra-39629-socuff%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3ECloud%20Shell%3C%2FA%3E%20inside%20the%20Azure%20Portal.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-2133247687%22%20id%3D%22toc-hId-2133251281%22%3EPowerShell%3A%20Get-AzRoleAssignment%3C%2FH2%3E%0A%3CP%3EAzure%20RBAC%20is%20supported%20by%20a%20number%20of%20PowerShell%20commands%2C%20but%20for%20this%20scenario%20our%20friend%20is%20%22%3CSTRONG%3EGet-AzRoleAssignment%3C%2FSTRONG%3E%22.%3C%2FP%3E%0A%3CP%3ELooking%20at%20the%20structure%20of%20PowerShell%2C%20because%20this%20is%20a%20%22%3CSTRONG%3EGet%3C%2FSTRONG%3E%22%20command%2C%20it's%20going%20to%20query%20Azure%20for%20some%20information%20and%20return%20the%20results%20to%20us.%20%22%3CSTRONG%3EAzRoleAssignment%3C%2FSTRONG%3E%22%20is%20the%20base%20for%20this%20command.%20The%20command%20also%20has%20a%20%22%3CSTRONG%3ENew-%3C%2FSTRONG%3E%22%20variation%2C%20for%20adding%20a%20new%20assignment%2C%20and%20a%20%22%3CSTRONG%3ERemove-%3C%2FSTRONG%3E%22%20variation%20for%20removing%20a%20role%20assignment.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3ENote%3A%3C%2FEM%3E%20If%20you%20see%20older%20blogs%20or%20scripts%20using%20%22Get-AzureRmRoleAssignment%22%2C%20that%20was%20an%20earlier%20name%20for%20this%20command%20before%20the%20Az%20updates.%20You%20can%20often%20replace%20the%20AzureRm%20bit%20with%20just%20Az%2C%20but%20not%20in%20every%20case%20as%20some%20commands%20have%20been%20deprecated.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20have%20multiple%20subscriptions%2C%20Cloud%20Shell%20will%20default%20to%20one%20of%20them%2C%20and%20your%20commands%20will%20query%20that%20subscription%20and%20it's%20associated%20resources.%20You%20can%20run%20%22%3CSTRONG%3EGet-AzContext%3C%2FSTRONG%3E%22%20to%20see%20which%20subscription%20is%20selected%2C%20and%20run%20%22%3CSTRONG%3ESet-AzContext%20-SubscriptionName%20%22My%20other%20subscription%22%22%3C%2FSTRONG%3E%20to%20change%20to%20a%20different%20one.%20(Note%20I've%20placed%20the%20actual%20name%20of%20my%20other%20subscription%20in%20it's%20own%20set%20of%20brackets%20because%20it%20has%20spaces%20in%20it).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet's%20start%20by%20just%20running%20this%20command%20and%20getting%20a%20list%20of%20all%20of%20the%20RBAC%20assignments%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EGet-AzRoleAssignment%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENext%2C%20let's%20narrow%20that%20down%20so%20we%20are%20only%20looking%20for%20role%20assignments%20for%20one%20particular%20user.%20The%20%3CSTRONG%3EGet-AzRoleAssignment%3C%2FSTRONG%3E%20command%20has%20a%20range%20of%20different%20parameters%20we%20can%20add%20which%20will%20act%20as%20a%20filter.%20We'll%20use%20%3CSTRONG%3ESignInName%3C%2FSTRONG%3E%2C%20which%20you%20can%20find%20in%20the%20user's%20details%20in%20Azure%20Active%20Directory%2C%20if%20you%20don't%20know%20the%20exact%20format%20(and%20replace%20my%20%3CEM%3Esteve.l%3C%2FEM%3E%20example%20name)%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EGet-AzRoleAssignment%20-SignInName%20steve.l%40scuffinozhotmail.onmicrosoft.com%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20gives%20us%20a%20long%20list%20of%20Steve's%20role%20assignments%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Get-AzRoleAssignment-DefaultDisplay.jpg%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F309189iF307DF080689C5BC%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Get-AzRoleAssignment-DefaultDisplay.jpg%22%20alt%3D%22The%20default%20display%20for%20Get-AzRoleAssignment%20for%20a%20single%20user%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EThe%20default%20display%20for%20Get-AzRoleAssignment%20for%20a%20single%20user%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20I%20want%20to%20play%20with%20the%20formatting%20to%20make%20it%20a%20little%20more%20readable%20onscreen.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20can%20format%20the%20output%20of%20this%20PowerShell%20command%20a%20few%20different%20ways%2C%20including%20as%20a%20list%20or%20as%20a%20table.%20The%20output%20above%20show%20sme%20all%20of%20the%20information%20that%20is%20returned%20by%20the%20query%20though%2C%20so%20I%20can%20use%20that%20to%20further%20refine%20the%20display%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EGet-AzRoleAssignment%20-SignInName%20steve.l%40scuffinozhotmail.onmicrosoft.com%20%7C%20FL%20DisplayName%2C%20RoleDefinitionName%2C%20Scope%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI'm%20using%20the%20'pipe'%20character%20of%20%7C%26nbsp%3B%20(which%20is%20Shift%20%2B%20%5C%20on%20my%20keyboard)%2C%20then%20the%20short%20version%20of%20the%20%22%3CSTRONG%3Eformat-list%3C%2FSTRONG%3E%22%20command%2C%20then%20I'm%20listing%20just%20the%20properties%20I%20want%20to%20be%20displayed%20(DisplayName%2C%20RoleDefinitionName%20and%20Scope).%20The%20pipe%20tells%20the%20first%20command%20to%20send%20it's%20output%20to%20the%20second%20command.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Get-AzRoleAssignment-FLDisplay.jpg%22%20style%3D%22width%3A%20991px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F309192i8A1199B3E600AB3B%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Get-AzRoleAssignment-FLDisplay.jpg%22%20alt%3D%22Get-AzRoleAssignment%20with%20the%20output%20formatted%20as%20a%20list%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EGet-AzRoleAssignment%20with%20the%20output%20formatted%20as%20a%20list%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20more%20formatting%20command%20examples%2C%20visit%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fpowershell%2Fscripting%2Fsamples%2Fusing-format-commands-to-change-output-view%3Fview%3Dpowershell-7.1%3Fwt.mc_id%3Dmodinfra-39629-socuff%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EUsing%20Format%20Commands%20to%20Change%20Output%20View%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHmm%2C%20that%20could%20still%20be%20a%20pretty%20long%20list%20if%20Steve%20had%20more%20role%20assignments.%20Let's%20try%20a%20table%20view%20instead%20with%20%22%3CSTRONG%3Eformat-table%3C%2FSTRONG%3E%22%20or%20FT%20for%20short%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EGet-AzRoleAssignment%20-SignInName%20steve.l%40scuffinozhotmail.onmicrosoft.com%20%7C%20FT%20DisplayName%2C%20RoleDefinitionName%2C%20Scope%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Get-AzRoleAssignment-FTDisplay.jpg%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F309194iE309009D383FC440%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Get-AzRoleAssignment-FTDisplay.jpg%22%20alt%3D%22Get-AzRoleAssignment%20formatted%20as%20a%20table%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EGet-AzRoleAssignment%20formatted%20as%20a%20table%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThat's%20better!%20So%2C%20Steve%20has%20a%20pretty%20high%20level%20of%20access%20at%20the%20top%20level%20of%20my%20subscription%20(Owner)%20plus%20a%20Log%20Analytics%20Reader%20role%20assignment%20which%20isn't%20needed%20-%20I%20can%20go%20and%20tidy%20that%20up.%20But%20if%20I%20run%20that%20same%20command%20for%20a%20different%20user%2C%20I'm%20seeing%20a%20different%20scope%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Sonia-RBAC-ManagementGroup.jpg%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F309196iE1C310B28CF7F69E%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Sonia-RBAC-ManagementGroup.jpg%22%20alt%3D%22Azure%20RBAC%20at%20the%20management%20group%20level%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EAzure%20RBAC%20at%20the%20management%20group%20level%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ESonia's%20account%20is%20showing%20the%20scope%20as%20the%20SCuffSubsMG%2C%20not%20the%20subscription%20ID.%20That's%20because%20her%20Owner%20access%20to%20the%20current%20subscription%20is%20determined%20by%20a%20role%20assignment%20that%20has%20been%20added%20at%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fgovernance%2Fmanagement-groups%2Foverview%3Fwt.mc_id%3Dmodinfra-39629-socuff%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Emanagement%20group%3C%2FA%3E%20level%2C%20and%20as%20this%20subscription%20belongs%20to%20that%20management%20group%2C%20the%20role%20assignment%20is%20inherited%20too.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere's%20one%20more%20important%20thing%20we%20need%20to%20include%20-%20what%20if%20our%20user%20is%20a%20member%20of%20a%20group%20that%20has%20been%20assigned%20a%20role%3F%20Our%20commands%20so%20far%20won't%20include%20that.%20We%20need%20to%20add%20%22%3CSTRONG%3E-ExpandPrincipalGroups%3C%2FSTRONG%3E%22.%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EGet-AzRoleAssignment%20-SignInName%20sarah.g%40scuffinozhotmail.onmicrosoft.com%20-ExpandPrincipalGroups%20%7C%20FL%20DisplayName%2C%20RoleDefinitionName%2C%20Scope%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22ExpandPrincipalGroups.jpg%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F309198i96D443532E49D9D2%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22ExpandPrincipalGroups.jpg%22%20alt%3D%22Get-AzRoleAssignment%20with%20ExpandPrincipalGroups%20for%20group%20membership%20role%20assignments%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EGet-AzRoleAssignment%20with%20ExpandPrincipalGroups%20for%20group%20membership%20role%20assignments%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ENow%20I%20can%20see%20that%20as%20well%20as%20being%20listed%20as%20an%20individual%20with%20the%20Virtual%20Machine%20Contributor%20role%20to%20VM%20CA01%2C%20Sarah%20is%20also%20a%20member%20of%20the%20IT_KeyVaultAdmins%20group%2C%20who%20have%20Key%20Vault%20Administrator%20access%20to%20the%20KV-BNE-01%20key%20vault.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1471158135%22%20id%3D%22toc-hId--1471154541%22%3EAzure%20deny%20assignments%3C%2FH3%3E%0A%3CP%3EThere's%20one%20type%20of%20Azure%20role%20assignment%20that%20won't%20display%20with%20Get-AzRoleAssignment%2C%20and%20that's%20an%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Frole-based-access-control%2Fdeny-assignments%3Fwt.mc_id%3Dmodinfra-39269-socuff%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EAzure%20deny%20assignment%3C%2FA%3E.%20You%20can't%20manually%20assign%20someone%20a%20deny%20assignment%20-%20they%20are%20created%20and%20used%20by%20Azure%20to%20protect%20system-managed%20resources.%20Azure%20Blueprints%20and%20Azure%20managed%20apps%20are%20the%20only%20way%20that%20they%20can%20be%20created.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20query%20where%20they%20are%20being%20used%20in%20your%20subscription%2C%20by%20using%20the%20%3CSTRONG%3EGet-AzDenyAssignment%3C%2FSTRONG%3E%20command.%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1481661239%22%20id%3D%22toc-hId--1481657645%22%3ELearn%20more%3C%2FH2%3E%0A%3CP%3ENow%20you've%20learnt%20about%20the%20capabilities%20and%20structure%20of%20this%20command%2C%20go%20and%20explore%20with%20different%20command%20parameters.%20If%20you%20get%20stuck%2C%20visit%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Frole-based-access-control%2Frole-assignments-list-powershell%3Fwt.mc_id%3Dmodinfra-39629-socuff%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EList%20Azure%20role%20assignments%20using%20PowerShell%3C%2FA%3E%26nbsp%3Bor%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Frole-based-access-control%2Frole-assignments-remove%3Fwt.mc_id%3Dmodinfra-39629-socuff%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ERemove%20Azure%20role%20assignments%3C%2FA%3E%20for%20more%20inspiration.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fpowershell%2Fmodule%2Faz.Resources%2FGet-azRoleAssignment%3Fwt.mc_id%3Dmodinfra-39629-socuff%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EGet-AzRoleAssignment%3C%2FA%3E%20has%20the%20full%20command%20syntax%2C%20parameters%2C%20inputs%20and%20outputs.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnd%20many%20of%20the%20basic%20PowerShell%20concepts%20we've%20explored%20here%2C%20like%20Get%2FSet%2FRemove%20and%20output%20formatting%2C%20are%20applicable%20to%20a%20ton%20of%20other%20PowerShell%20commands%20too.%20You're%20now%20on%20your%20way%20to%20understanding%20and%20exploring%20more%20of%20PowerShell%2C%20especially%20for%20scenarios%20where%20you%20can't%20easily%20retrieve%20the%20same%20information%20in%20the%20Azure%20portal.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2735382%22%20slang%3D%22en-US%22%3E%3CP%3EHow%20to%20list%20the%20role%20based%20access%20control%20assignments%20for%20a%20specific%20user%2C%20including%20the%20structure%20of%20the%20PowerShell%20commands.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Title-card.jpg%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F309211i5B2E5FA337C3DF16%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Title-card.jpg%22%20alt%3D%22Title-card.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2735382%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎Sep 09 2021 02:57 AM
Updated by: