@@ -14,7 +14,7 @@ function Get-CippSamPermissions {
1414 Internal
1515 #>
1616 [CmdletBinding (DefaultParameterSetName = ' Default' )]
17- Param (
17+ param (
1818 [Parameter (ParameterSetName = ' ManifestOnly' )]
1919 [switch ]$ManifestOnly ,
2020 [Parameter (ParameterSetName = ' Default' )]
@@ -24,11 +24,19 @@ function Get-CippSamPermissions {
2424 )
2525
2626 if (! $SavedOnly.IsPresent ) {
27+ # Return cached result if available and less than 5 minutes old (avoids duplicate partner-tenant Graph calls within same invocation)
28+ if ($NoDiff.IsPresent -and $script :CippSamPermissionsCache -and
29+ $script :CippSamPermissionsCacheTime -and
30+ ((Get-Date ) - $script :CippSamPermissionsCacheTime ).TotalMinutes -lt 5 ) {
31+ return $script :CippSamPermissionsCache
32+ }
33+
2734 $ModuleBase = Get-Module - Name CIPPCore | Select-Object - ExpandProperty ModuleBase
2835 $SamManifestFile = Get-Item (Join-Path $ModuleBase ' lib\data\SAMManifest.json' )
2936 $AdditionalPermissions = Get-Item (Join-Path $ModuleBase ' lib\data\AdditionalPermissions.json' )
3037
3138 $ServicePrincipalList = New-GraphGetRequest - Uri ' https://graph.microsoft.com/beta/servicePrincipals?$top=999&$select=id,appId,displayName' - tenantid $env: TenantID - NoAuthCheck $true
39+
3240 $SAMManifest = Get-Content - Path $SamManifestFile.FullName | ConvertFrom-Json
3341 $AdditionalPermissions = Get-Content - Path $AdditionalPermissions.FullName | ConvertFrom-Json
3442
@@ -191,6 +199,11 @@ function Get-CippSamPermissions {
191199
192200 $SamAppPermissions = $SamAppPermissions | ConvertTo-Json - Depth 10 - Compress | ConvertFrom-Json
193201
202+ if ($NoDiff.IsPresent ) {
203+ $script :CippSamPermissionsCache = $SamAppPermissions
204+ $script :CippSamPermissionsCacheTime = Get-Date
205+ }
206+
194207 return $SamAppPermissions
195208}
196209
0 commit comments