@@ -15,7 +15,7 @@ function Invoke-ExecSAMAppPermissions {
1515 $Entity = @ {
1616 ' PartitionKey' = ' CIPP-SAM'
1717 ' RowKey' = ' CIPP-SAM'
18- ' Permissions' = [string ]($Permissions | ConvertTo-Json - Depth 10 - Compress)
18+ ' Permissions' = [string ]($Permissions.Permissions | ConvertTo-Json - Depth 10 - Compress)
1919 }
2020 $Table = Get-CIPPTable - TableName ' AppPermissions'
2121 $null = Add-CIPPAzDataTableEntity @Table - Entity $Entity - Force
@@ -29,77 +29,7 @@ function Invoke-ExecSAMAppPermissions {
2929 }
3030 }
3131 default {
32- $ModuleBase = Get-Module - Name CIPPCore | Select-Object - ExpandProperty ModuleBase
33- $SamManifest = Get-Item " $ModuleBase \Public\SAMManifest.json"
34- $AdditionalPermissions = Get-Item " $ModuleBase \Public\AdditionalPermissions.json"
35-
36- $LastWrite = @ {
37- ' SAMManifest' = $SamManifest.LastWriteTime
38- ' AdditionalPermissions' = $AdditionalPermissions.LastWriteTime
39- }
40-
41- $ServicePrincipals = New-GraphGetRequest - Uri ' https://graph.microsoft.com/beta/servicePrincipals?$top=999&$select=appId,displayName,appRoles,publishedPermissionScopes' - tenantid $env: TenantID - NoAuthCheck $true
42- $SAMManifest = Get-Content - Path $SamManifest.FullName | ConvertFrom-Json
43- $AdditionalPermissions = Get-Content - Path $AdditionalPermissions.FullName | ConvertFrom-Json
44-
45- $RequiredResources = $SamManifest.requiredResourceAccess
46-
47- $AppIds = ($RequiredResources.resourceAppId + $AdditionalPermissions.resourceAppId ) | Sort-Object - Unique
48-
49- $Permissions = @ {}
50- foreach ($AppId in $AppIds ) {
51- $ServicePrincipal = $ServicePrincipals | Where-Object - Property appId -EQ $AppId
52- $AppPermissions = [System.Collections.Generic.List [object ]]@ ()
53- $ManifestPermissions = ($RequiredResources | Where-Object - Property resourceAppId -EQ $AppId ).resourceAccess
54- $UnpublishedPermissions = ($AdditionalPermissions | Where-Object - Property resourceAppId -EQ $AppId ).resourceAccess
55-
56- foreach ($Permission in $ManifestPermissions ) {
57- $AppPermissions.Add ($Permission )
58- }
59- if ($UnpublishedPermissions ) {
60- foreach ($Permission in $UnpublishedPermissions ) {
61- $AppPermissions.Add ($Permission )
62- }
63- }
64-
65- $ApplicationPermissions = [system.collections.generic.list [object ]]@ ()
66- $DelegatedPermissions = [system.collections.generic.list [object ]]@ ()
67- foreach ($Permission in $AppPermissions ) {
68- if ($Permission.id -match ' ^[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}$' ) {
69- if ($Permission.type -eq ' Role' ) {
70- $PermissionName = ($ServicePrincipal.appRoles | Where-Object - Property id -EQ $Permission.id ).value
71- } else {
72- $PermissionName = ($ServicePrincipal.publishedPermissionScopes | Where-Object - Property id -EQ $Permission.id ).value
73- }
74- } else {
75- $PermissionName = $Permission.id
76- }
77-
78- if ($Permission.type -eq ' Role' ) {
79- $ApplicationPermissions.Add ([PSCustomObject ]@ {
80- id = $Permission.id
81- value = $PermissionName
82-
83- })
84- } else {
85- $DelegatedPermissions.Add ([PSCustomObject ]@ {
86- id = $Permission.id
87- value = $PermissionName
88- })
89- }
90- }
91-
92- $ServicePrincipal = $ServicePrincipals | Where-Object - Property appId -EQ $AppId
93- $Permissions .$AppId = @ {
94- applicationPermissions = @ ($ApplicationPermissions | Sort-Object - Property label)
95- delegatedPermissions = @ ($DelegatedPermissions | Sort-Object - Property label)
96- }
97- }
98-
99- $Body = @ {
100- ' Permissions' = $Permissions
101- ' LastUpdate' = $LastWrite
102- }
32+ $Body = Get-CippSamPermissions
10333 }
10434 }
10535
0 commit comments