SOLVED

How to list azure resources which have inheriting access and direct access using powershell

%3CLINGO-SUB%20id%3D%22lingo-sub-2023067%22%20slang%3D%22en-US%22%3EHow%20to%20list%20azure%20resources%20which%20have%20inheriting%20access%20and%20direct%20access%20using%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2023067%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20it%20really%20possible%20to%20list%20azure%20resources%20which%20have%20inherited%20access%20and%20direct%20access%20using%20Powershell%3F%20I%20couldn't%20find%20any%20azure%20PowerShell%20command%20which%20shows%20at%20least%20any%20column%20which%20has%20this%20information.%20Can%20anyone%20help%20me%20here%2C%20please%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2023067%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Eazure%20powershell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Epowershell%20script%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2023589%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20list%20azure%20resources%20which%20have%20inheriting%20access%20and%20direct%20access%20using%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2023589%22%20slang%3D%22en-US%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F810782%22%20target%3D%22_blank%22%3E%40AlphaBetaGamma%3C%2FA%3E%2C%3C%2FP%3E%3CP%3EYou%20can%20use%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Faz.resources%2Fget-azroleassignment%3Fview%3Dazps-5.2.0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EGet-AzRoleAssignment%3C%2FA%3E%20cmdlet%20which%20lists%20Azure%20RBAC%20role%20assignments%20at%20the%20specified%20scope.%3C%2FP%3E%3CP%3EField%20that%20you%20are%20looking%20for%20is%20%3CSTRONG%3EScope%3C%2FSTRONG%3E.%3C%2FP%3E%3CP%3EScope%20shows%20at%20what%20level%20permission%20have%20been%20assigned.%3C%2FP%3E%3CP%3EFor%20example%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EPS%20C%3A%5C%26gt%3B%20Get-AzRoleAssignment%0A%0ARoleAssignmentId%20%20%20%3A%20%2Fsubscriptions%2F00000000-0000-0000-0000-000000000000%2Fproviders%2FMicrosoft.Authorization%2FroleAssignments%2F11111111-1111-1111-1111-111111111111%0AScope%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3A%20%2Fsubscriptions%2F00000000-0000-0000-0000-000000000000%0ADisplayName%20%20%20%20%20%20%20%20%3A%20Alain%0ASignInName%20%20%20%20%20%20%20%20%20%3A%20alain%40example.com%0ARoleDefinitionName%20%3A%20Storage%20Blob%20Data%20Reader%0ARoleDefinitionId%20%20%20%3A%202a2b9908-6ea1-4ae2-8e65-a410df84e7d1%0AObjectId%20%20%20%20%20%20%20%20%20%20%20%3A%2044444444-4444-4444-4444-444444444444%0AObjectType%20%20%20%20%20%20%20%20%20%3A%20User%0ACanDelegate%20%20%20%20%20%20%20%20%3A%20False%0A%0ARoleAssignmentId%20%20%20%3A%20%2Fsubscriptions%2F00000000-0000-0000-0000-000000000000%2FresourceGroups%2Fpharma-sales%2Fproviders%2FMicrosoft.Authorization%2FroleAssignments%2F33333333-3333-3333-3333-333333333333%0AScope%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3A%20%2Fsubscriptions%2F00000000-0000-0000-0000-000000000000%2FresourceGroups%2Fpharma-sales%0ADisplayName%20%20%20%20%20%20%20%20%3A%20Marketing%0ASignInName%20%20%20%20%20%20%20%20%20%3A%0ARoleDefinitionName%20%3A%20Contributor%0ARoleDefinitionId%20%20%20%3A%20b24988ac-6180-42a0-ab88-20f7382dd24c%0AObjectId%20%20%20%20%20%20%20%20%20%20%20%3A%2022222222-2222-2222-2222-222222222222%0AObjectType%20%20%20%20%20%20%20%20%20%3A%20Group%0ACanDelegate%20%20%20%20%20%20%20%20%3A%20False%0A%0A...%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe%20see%202%20assignments%3A%3C%2FP%3E%3CP%3E1)%20Role%3A%20%3CSTRONG%3EStorage%20Blob%20Data%20Reader%3C%2FSTRONG%3E%20is%20assigned%20for%20%3CSTRONG%3Euser%20Allain%3C%2FSTRONG%3E%20at%20subscription%20level%20(based%20on%20scope%20value)%20and%20will%20be%20inherited%20for%20all%20resources%20in%20the%20subscription%3C%2FP%3E%3CP%3E2)%20Role%3A%20%3CSTRONG%3EContributor%3C%2FSTRONG%3E%20is%20assigned%20for%20%3CSTRONG%3EMarketing%20group%3C%2FSTRONG%3E%20at%20resource%20group%20level%20and%20will%20be%20inherited%20for%20all%20resources%20in%20pharma-sales%20resource%20group.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CUL%3E%3CLI%3EReference%3A%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Frole-based-access-control%2Frole-assignments-list-powershell%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EList%20Azure%20role%20assignments%20using%20Azure%20PowerShell%3C%2FA%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3EHope%20that%20helps.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2024596%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20list%20azure%20resources%20which%20have%20inheriting%20access%20and%20direct%20access%20using%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2024596%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F672105%22%20target%3D%22_blank%22%3E%40AndySvints%3C%2FA%3E%26nbsp%3BThanks%20a%20mil%20for%20your%20response.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYes%2C%20that%20will%20help%20to%20list%20the%20resources%20which%20have%20inherited%20access%20and%20direct%20access.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJust%20messing%20around%20a%20bit%20and%20came%20up%20with%20something%20if%20we%20wish%20to%20pull%20out%20the%20exact%20resource%20name%20which%20has%20inherited%20access%20and%20exact%20resource%20name%20with%20direct%20access.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EProcedure%201%3A%26nbsp%3B%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%23%26nbsp%3Bto%26nbsp%3Blist%26nbsp%3Bresources%26nbsp%3Bwhich%26nbsp%3Bhave%26nbsp%3Binherited%26nbsp%3Baccess%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24inhaccess%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EGet-AzRoleAssignment%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%7C%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EWhere-Object%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%7B%3C%2FSPAN%3E%3CSPAN%3E%24_%3C%2FSPAN%3E%3CSPAN%3E.Scope%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B-ne%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%22%2Fsubscriptions%2F00000000-0000-0000-0000-000000000000%22%3C%2FSPAN%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24inhaccess%20%7C%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EFormat-Table%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3BDisplayName%2C%26nbsp%3BRoleDefinitionName%2C%26nbsp%3BScope%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%23%26nbsp%3Bto%26nbsp%3Blist%26nbsp%3Bresources%26nbsp%3Bwhich%26nbsp%3Bhave%26nbsp%3Bdirect%20access%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24diraccess%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EGet-AzRoleAssignment%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%7C%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EWhere-Object%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%7B%3C%2FSPAN%3E%3CSPAN%3E%24_%3C%2FSPAN%3E%3CSPAN%3E.Scope%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B-eq%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%22%2Fsubscriptions%2F00000000-0000-0000-0000-000000000000%22%3C%2FSPAN%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24diraccess%20%7C%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EFormat-Table%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3BDisplayName%2C%26nbsp%3BRoleDefinitionName%2C%26nbsp%3BScope%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EProcedure%202%3A%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%23to%26nbsp%3Blist%26nbsp%3Bexact%26nbsp%3Bresource%26nbsp%3Bwhich%26nbsp%3Bhave%26nbsp%3Binherited%26nbsp%3Baccess%26nbsp%3Balong%26nbsp%3Bwith%26nbsp%3Bits%26nbsp%3BDisplayname%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eforeach%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B(%3C%2FSPAN%3E%3CSPAN%3E%24Resource%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3Ein%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EGet-AzResource%3C%2FSPAN%3E%3CSPAN%3E)%26nbsp%3B%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%24RoleAssignments%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3EGet-AzRoleAssignment%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%7C%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EWhere-Object%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%7B%3C%2FSPAN%3E%3CSPAN%3E%24_%3C%2FSPAN%3E%3CSPAN%3E.Scope%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B-ne%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%22%2Fsubscriptions%2F00000000-0000-0000-0000-000000000000%22%3C%2FSPAN%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EForEach%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B(%3C%2FSPAN%3E%3CSPAN%3E%24RoleAssignment%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3Ein%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%24RoleAssignments%3C%2FSPAN%3E%3CSPAN%3E)%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%24Resource%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%7C%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3ESelect-Object%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%40%3C%2FSPAN%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3CSPAN%3EName%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%22Azure%26nbsp%3BResource%26nbsp%3Bname%22%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3CSPAN%3EExpression%3C%2FSPAN%3E%3CSPAN%3E%3D%7B%3C%2FSPAN%3E%3CSPAN%3E%24Resource%3C%2FSPAN%3E%3CSPAN%3E.Name%3C%2FSPAN%3E%3CSPAN%3E%7D%7D%2C%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%40%3C%2FSPAN%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3CSPAN%3EName%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%22DisplayName%22%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3CSPAN%3EExpression%3C%2FSPAN%3E%3CSPAN%3E%3D%7B%3C%2FSPAN%3E%3CSPAN%3E%24RoleAssignment%3C%2FSPAN%3E%3CSPAN%3E.DisplayName%3C%2FSPAN%3E%3CSPAN%3E%7D%7D%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EBut%2C%20I'm%20just%20confused%20if%20this%20is%20the%20correct%20way%20to%20pull%20only%20resource%20name%20which%20has%20inherited%20access%20and%20resource%20name%20with%20direct%20access%3F%20Do%20you%20think%20the%20above%20is%20correct%20or%20else%20am%20I%20missing%20anything%20here%3F%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2025012%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20list%20azure%20resources%20which%20have%20inheriting%20access%20and%20direct%20access%20using%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2025012%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F810782%22%20target%3D%22_blank%22%3E%40AlphaBetaGamma%3C%2FA%3E%2C%3C%2FP%3E%3CP%3EIt%20is%20partially%20correct.%3C%2FP%3E%3CP%3EYour%20code%20is%20assuming%20that%20permissions%20can%20be%20inherited%20only%20from%20Subscription%20level%20which%20is%20not%20true.%3C%2FP%3E%3CP%3EThere%20also%20might%20be%20assignments%20on%20the%20resource%20group%20level%20which%20will%20be%20inherited%20also.%3C%2FP%3E%3CP%3EAs%20mentioned%20in%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Frole-based-access-control%2Frole-assignments-list-powershell%23list-role-assignments-for-a-resource%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EList%20role%20assignments%20for%20a%20resource%3C%2FA%3E%20to%26nbsp%3Bget%26nbsp%3Bpermissions%20directly%20assigned%20to%20a%20resource(storage%20account)%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EPS%20C%3A%5C%26gt%3B%20Get-AzRoleAssignment%20%7C%20Where-Object%20%7B%24_.Scope%20-eq%20%22%2Fsubscriptions%2F00000000-0000-0000-0000-000000000000%2Fresourcegroups%2Fstorage-test-rg%2Fproviders%2FMicrosoft.Storage%2FstorageAccounts%2Fstoragetest0122%22%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EIf%20you%20change%20%3CSTRONG%3EWhere-Object%3C%2FSTRONG%3E%20condition%20from%20%3CSTRONG%3Eequal%3C%2FSTRONG%3E%20to%20%3CSTRONG%3Enot%20equal%3C%2FSTRONG%3E%20you%20will%20get%20inherited%20permissions.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20that%20helps.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2025852%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20list%20azure%20resources%20which%20have%20inheriting%20access%20and%20direct%20access%20using%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2025852%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F672105%22%20target%3D%22_blank%22%3E%40AndySvints%3C%2FA%3E%26nbsp%3BThanks%20for%20your%20response.%20Yes%2C%20we%20can%20see%20the%20inherited%20access%2Fdirect%20access%20for%20each%20resource%20with%20the%20help%20of%20below%20one%2C%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CPRE%3EGet-AzRoleAssignment%20%7C%20Where-Object%20%7B%24_.Scope%20-eq%20%22%2Fsubscriptions%2F00000000-0000-0000-0000-000000000000%2Fresourcegroups%2Fstorage-test-rg%2Fproviders%2FMicrosoft.Storage%2FstorageAccounts%2Fstoragetest0122%22%7D%E2%80%8B%3C%2FPRE%3E%3CP%3EBut%2C%20what%20if%20we%20wish%20to%20see%20a%20list%20of%20all%20azure%20resources%20which%20have%20inherited%20access%20and%20a%20list%20of%20azure%20resources%20with%20direct%20access.%20Something%20like%20this%20as%20a%20sample%20output%3CBR%20%2F%3EList%20of%20azure%20resources%20which%20have%20inherited%20access%3C%2FP%3E%3CTABLE%20width%3D%22182%22%3E%3CTBODY%3E%3CTR%3E%3CTD%20width%3D%2298%22%3EResource%20name%3C%2FTD%3E%3CTD%20width%3D%2284%22%3EDisplayName%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3Ekeyvault%3C%2FTD%3E%3CTD%3ETom%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3Esql%3C%2FTD%3E%3CTD%3EJeremy%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EList%20of%20Azure%20resources%20which%20have%20direct%20access%3C%2FP%3E%3CTABLE%20width%3D%22182%22%3E%3CTBODY%3E%3CTR%3E%3CTD%20width%3D%2298%22%3EResource%20name%3C%2FTD%3E%3CTD%20width%3D%2284%22%3EDisplayName%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ELog%20analytics%3C%2FTD%3E%3CTD%3Ejack%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EVM%3C%2FTD%3E%3CTD%3EJones%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2027145%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20list%20azure%20resources%20which%20have%20inheriting%20access%20and%20direct%20access%20using%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2027145%22%20slang%3D%22en-US%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F810782%22%20target%3D%22_blank%22%3E%40AlphaBetaGamma%3C%2FA%3E%2C%3C%2FP%3E%3CP%3EHere%20is%20quick%20and%20dirty%20way%20to%20get%20what%20you%20need%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24Resource%3DGet-AzResource%0A%24RoleAssignments%3DNew-Object%20System.Collections.Generic.List%5BPSObject%5D%0Aforeach(%24r%20in%20%24Resource)%7B%0A%20%20%20%20%24Assignment%3DGet-AzRoleAssignment%20-ResourceName%20%24r.Name%20-ResourceGroupName%20%24r.ResourceGroupName%20-ResourceType%20%24r.ResourceType%0A%20%20%20%20foreach(%24a%20in%20%24Assignment)%7B%0A%20%20%20%20%20%20%20%20%24IsInherited%3Dif(%24r.ResourceId%20-eq%20%24a.Scope)%7B%24false%7Delse%7B%24true%7D%0A%0A%20%20%20%20%20%20%20%24a%20%7C%20Add-member%20-NotePropertyName%20ResourceName%20-NotePropertyValue%20%24r.Name%0A%20%20%20%20%20%20%20%20%24a%20%7C%20Add-member%20-NotePropertyName%20ResourceId%20-NotePropertyValue%20%24r.ResourceId%0A%20%20%20%20%20%20%20%24a%20%7C%20Add-member%20-NotePropertyName%20IsInherited%20-NotePropertyValue%20%24IsInherited%0A%20%20%20%20%20%20%20%24RoleAssignments.Add(%24a)%0A%20%20%20%20%7D%0A%7D%0A%24RoleAssignments%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPseudo%20code%3A%3C%2FP%3E%3COL%3E%3CLI%3EGet%20all%20az%20resources%3C%2FLI%3E%3CLI%3EFor%20each%20resource%20run%20get%20az%20role%20assignments%3C%2FLI%3E%3CLI%3ELoop%20trough%20role%20assignments%20and%20add%20IsInherited%20property%3A%3CBR%20%2F%3EIf%20scope%20eq%20resourceid%20then%20false%20otherwise%20true%3C%2FLI%3E%3CLI%3EAdd%20ResourceName%20and%20ID%20to%20resulting%20object%3C%2FLI%3E%3CLI%3EAdd%20results%20to%20List%3C%2FLI%3E%3C%2FOL%3E%3CP%3EAt%20the%20end%20you%20will%20get%20list%20of%20all%20Role%20Assignments%20with%20additional%20info(ResourceName%2C%20ResourceID%20and%20IsInherited%20flag).%3C%2FP%3E%3CP%3EThen%20you%20can%20easily%20rotate%20data%20as%20needed.%3C%2FP%3E%3CP%3EList%20Direct%20Assignments%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%23Direct%20Assignments%0A%24RoleAssignments%20%20%7Cwhere%20%7B%24_.isinherited%20-eq%20%24false%7D%20%7Cselect%20ResourceName%2C%20DisplayName%2C%20RoleDefinitionName%2C%20IsInherited%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EList%20Inherited%20Assignments%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%23Inherited%20ones%0A%24RoleAssignments%20%20%7Cwhere%20%7B%24_.isinherited%20-ne%20%24false%7D%20%7Cselect%20ResourceName%2C%20DisplayName%2C%20RoleDefinitionName%2C%20IsInherited%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGeneral%20stats%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24RoleAssignments.isinherited%20%20%7Cgroup%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20783px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F243708i9C71E12FC6FBCF04%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20that%20helps.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hi,

 

Is it really possible to list azure resources which have inherited access and direct access using Powershell? I couldn't find any azure PowerShell command which shows at least any column which has this information. Can anyone help me here, please?

5 Replies

Hello @AlphaBetaGamma,

You can use Get-AzRoleAssignment cmdlet which lists Azure RBAC role assignments at the specified scope.

Field that you are looking for is Scope.

Scope shows at what level permission have been assigned.

For example:

PS C:\> Get-AzRoleAssignment

RoleAssignmentId   : /subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleAssignments/11111111-1111-1111-1111-111111111111
Scope              : /subscriptions/00000000-0000-0000-0000-000000000000
DisplayName        : Alain
SignInName         : alain@example.com
RoleDefinitionName : Storage Blob Data Reader
RoleDefinitionId   : 2a2b9908-6ea1-4ae2-8e65-a410df84e7d1
ObjectId           : 44444444-4444-4444-4444-444444444444
ObjectType         : User
CanDelegate        : False

RoleAssignmentId   : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/pharma-sales/providers/Microsoft.Authorization/roleAssignments/33333333-3333-3333-3333-333333333333
Scope              : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/pharma-sales
DisplayName        : Marketing
SignInName         :
RoleDefinitionName : Contributor
RoleDefinitionId   : b24988ac-6180-42a0-ab88-20f7382dd24c
ObjectId           : 22222222-2222-2222-2222-222222222222
ObjectType         : Group
CanDelegate        : False

...

 

We see 2 assignments:

1) Role: Storage Blob Data Reader is assigned for user Allain at subscription level (based on scope value) and will be inherited for all resources in the subscription

2) Role: Contributor is assigned for Marketing group at resource group level and will be inherited for all resources in pharma-sales resource group.

 

Hope that helps.

@AndySvints Thanks a mil for your response.

 

Yes, that will help to list the resources which have inherited access and direct access. 

 

Just messing around a bit and came up with something if we wish to pull out the exact resource name which has inherited access and exact resource name with direct access. 

 

Procedure 1: 

# to list resources which have inherited access
$inhaccess = Get-AzRoleAssignment | Where-Object {$_.Scope -ne "/subscriptions/00000000-0000-0000-0000-000000000000"}
$inhaccess | Format-Table DisplayName, RoleDefinitionName, Scope
 
# to list resources which have direct access
$diraccess = Get-AzRoleAssignment | Where-Object {$_.Scope -eq "/subscriptions/00000000-0000-0000-0000-000000000000"}
$diraccess | Format-Table DisplayName, RoleDefinitionName, Scope
 
Procedure 2:
#to list exact resource which have inherited access along with its Displayname
foreach ($Resource in Get-AzResource) {
    $RoleAssignments=Get-AzRoleAssignment | Where-Object {$_.Scope -ne "/subscriptions/00000000-0000-0000-0000-000000000000"}
    ForEach ($RoleAssignment in $RoleAssignments){
      $Resource | Select-Object @{Name="Azure Resource name";Expression={$Resource.Name}},      
        @{Name="DisplayName";Expression={$RoleAssignment.DisplayName}}   
    }
   }
 
But, I'm just confused if this is the correct way to pull only resource name which has inherited access and resource name with direct access? Do you think the above is correct or else am I missing anything here?

@AlphaBetaGamma,

It is partially correct.

Your code is assuming that permissions can be inherited only from Subscription level which is not true.

There also might be assignments on the resource group level which will be inherited also.

As mentioned in List role assignments for a resource to get permissions directly assigned to a resource(storage account):

PS C:\> Get-AzRoleAssignment | Where-Object {$_.Scope -eq "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/storage-test-rg/providers/Microsoft.Storage/storageAccounts/storagetest0122"}

If you change Where-Object condition from equal to not equal you will get inherited permissions. 

 

Hope that helps.

@AndySvints Thanks for your response. Yes, we can see the inherited access/direct access for each resource with the help of below one,

Get-AzRoleAssignment | Where-Object {$_.Scope -eq "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/storage-test-rg/providers/Microsoft.Storage/storageAccounts/storagetest0122"}​

But, what if we wish to see a list of all azure resources which have inherited access and a list of azure resources with direct access. Something like this as a sample output
List of azure resources which have inherited access

Resource nameDisplayName
keyvaultTom
sqlJeremy

 

List of Azure resources which have direct access

Resource nameDisplayName
Log analyticsjack
VMJones




 

Best Response confirmed by AlphaBetaGamma (Occasional Contributor)
Solution

Hello @AlphaBetaGamma,

Here is quick and dirty way to get what you need:

$Resource=Get-AzResource
$RoleAssignments=New-Object System.Collections.Generic.List[PSObject]
foreach($r in $Resource){
    $Assignment=Get-AzRoleAssignment -ResourceName $r.Name -ResourceGroupName $r.ResourceGroupName -ResourceType $r.ResourceType
    foreach($a in $Assignment){
        $IsInherited=if($r.ResourceId -eq $a.Scope){$false}else{$true}

       $a | Add-member -NotePropertyName ResourceName -NotePropertyValue $r.Name
        $a | Add-member -NotePropertyName ResourceId -NotePropertyValue $r.ResourceId
       $a | Add-member -NotePropertyName IsInherited -NotePropertyValue $IsInherited
       $RoleAssignments.Add($a)
    }
}
$RoleAssignments

 

Pseudo code:

  1. Get all az resources
  2. For each resource run get az role assignments
  3. Loop trough role assignments and add IsInherited property:
    If scope eq resourceid then false otherwise true
  4. Add ResourceName and ID to resulting object
  5. Add results to List

At the end you will get list of all Role Assignments with additional info(ResourceName, ResourceID and IsInherited flag).

Then you can easily rotate data as needed.

List Direct Assignments:

#Direct Assignments
$RoleAssignments  |where {$_.isinherited -eq $false} |select ResourceName, DisplayName, RoleDefinitionName, IsInherited

 

List Inherited Assignments:

#Inherited ones
$RoleAssignments  |where {$_.isinherited -ne $false} |select ResourceName, DisplayName, RoleDefinitionName, IsInherited

 

General stats:

$RoleAssignments.isinherited  |group

image.png

 

 

Hope that helps.