powershellcommand-line-interfaceazure-rbacrole-based-access-controlazure-identity

How to filter custom directory roles from Powershell Or CLI


I have few custom directory roles with specific permissions. I attempted to do it from graph but no use, throwing errors.

Is there any other possible way to get that list from Powershell Or CLI.

Get-AzRoleDefinition

Getting all roles, how to add custom role filter for this command?


Solution

  • I tried to reproduce the same in my environment to get the custom roles using PowerShell

    Here is the script to get Azure custom roles with Filter.

    #import and Install Az Module
    Import-Module Az.Accounts
    Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
    #connect-Azure Account
    Connect-AzAccount
    #Get All Azure AzRoleDefinition
    Get-AzRoleDefinition
    Get-AzRoleDefinition -Name Reader
    #Get Custom Roles
    Get-AzRoleDefinition -Custom |? {$_.IsCustom -eq $true}| FT Name,IsCustom,Id
    
    
    
    
     
    

    Output with Filter command.

    enter image description here

    Reference : Azure custom role using Azure PowerShell