Skip to content

Commit e95b5f3

Browse files
add caching for tenant capabilities
1 parent eefe7bd commit e95b5f3

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Modules/CIPPCore/Public/Functions/Test-CIPPStandardLicense.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ function Test-CIPPStandardLicense {
4444
Write-LogMessage -API 'Standards' -tenant $TenantFilter -message "Tenant does not have the required capability to run standard $StandardName`: The tenant needs one of the following service plans: $($RequiredCapabilities -join ',')" -sev Error
4545
Set-CIPPStandardsCompareField -FieldName "standards.$StandardName" -FieldValue "License Missing: This tenant is not licensed for the following capabilities: $($RequiredCapabilities -join ',')" -Tenant $TenantFilter
4646
Write-Host "Tenant does not have the required capability to run standard $StandardName - $($RequiredCapabilities -join ','). Exiting"
47-
exit 0
47+
return $false
4848
}
4949
Write-Host "Tenant has the required capabilities for standard $StandardName"
50+
return $true
5051
} catch {
5152
Write-LogMessage -API 'Standards' -tenant $TenantFilter -message "Error checking license capabilities for standard $StandardName`: $($_.Exception.Message)" -sev Error
5253
Set-CIPPStandardsCompareField -FieldName "standards.$StandardName" -FieldValue "License Missing: Error checking license capabilities - $($_.Exception.Message)" -Tenant $TenantFilter
53-
exit 0
54+
return $false
5455
}
5556
}

Modules/CIPPCore/Public/Get-CIPPTenantCapabilities.ps1

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,21 @@ function Get-CIPPTenantCapabilities {
66
$APIName = 'Get Tenant Capabilities',
77
$Headers
88
)
9-
10-
$Org = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/subscribedSkus' -tenantid $TenantFilter
9+
$ConfigTable = Get-CIPPTable -TableName 'CacheCapabilities'
10+
$datetime = (Get-Date).AddDays(-1).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
11+
$ConfigEntries = Get-CIPPAzDataTableEntity @ConfigTable -Filter "RowKey eq '$TenantFilter' and Timestamp ge datetime'$datetime'"
12+
if ($ConfigEntries) {
13+
$Org = $ConfigEntries.JSON | ConvertFrom-Json
14+
} else {
15+
$Org = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/subscribedSkus' -tenantid $TenantFilter
16+
# Save the capabilities to the cache table
17+
$Entity = @{
18+
PartitionKey = 'Capabilities'
19+
RowKey = $TenantFilter
20+
JSON = "$($Org | ConvertTo-Json -Compress -Depth 10)"
21+
}
22+
Add-CIPPAzDataTableEntity @ConfigTable -Entity $Entity -Force
23+
}
1124
$Plans = $Org.servicePlans | Where-Object { $_.provisioningStatus -eq 'Success' } | Sort-Object -Property serviceplanName -Unique | Select-Object servicePlanName, provisioningStatus
1225
$Results = @{}
1326
foreach ($Plan in $Plans) {

0 commit comments

Comments
 (0)