Skip to content

Commit c96e480

Browse files
skip requests for tenants that don't have licenses
1 parent ad7cf96 commit c96e480

File tree

2 files changed

+113
-106
lines changed

2 files changed

+113
-106
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function Test-CIPPStandardLicense {
3737
$TenantCapabilities = Get-CIPPTenantCapabilities -TenantFilter $TenantFilter
3838

3939
$Capabilities = foreach ($Capability in $RequiredCapabilities) {
40-
Write-Host "Checking capability: $Capability"
40+
Write-Verbose "Checking capability: $Capability"
4141
if ($TenantCapabilities.$Capability -eq $true) {
4242
$Capability
4343
}
@@ -47,11 +47,11 @@ function Test-CIPPStandardLicense {
4747
if (!$SkipLog.IsPresent) {
4848
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
4949
Set-CIPPStandardsCompareField -FieldName "standards.$StandardName" -FieldValue "License Missing: This tenant is not licensed for the following capabilities: $($RequiredCapabilities -join ',')" -Tenant $TenantFilter
50-
Write-Host "Tenant does not have the required capability to run standard $StandardName - $($RequiredCapabilities -join ','). Exiting"
50+
Write-Verbose "Tenant does not have the required capability to run standard $StandardName - $($RequiredCapabilities -join ','). Exiting"
5151
}
5252
return $false
5353
}
54-
Write-Host "Tenant has the required capabilities for standard $StandardName"
54+
Write-Verbose "Tenant has the required capabilities for standard $StandardName"
5555
return $true
5656
} catch {
5757
if (!$SkipLog.IsPresent) {

Modules/CIPPCore/Public/Get-CIPPDrift.ps1

Lines changed: 110 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,41 @@ function Get-CIPPDrift {
2929
[switch]$AllTenants
3030
)
3131

32-
32+
$IntuneCapable = Test-CIPPStandardLicense -StandardName 'IntuneTemplate_general' -TenantFilter $TenantFilter -RequiredCapabilities @('INTUNE_A', 'MDM_Services', 'EMS', 'SCCM', 'MICROSOFTINTUNEPLAN1')
33+
$ConditionalAccessCapable = Test-CIPPStandardLicense -StandardName 'ConditionalAccessTemplate_general' -TenantFilter $TenantFilter -RequiredCapabilities @('AAD_PREMIUM', 'AAD_PREMIUM_P2')
3334
$IntuneTable = Get-CippTable -tablename 'templates'
34-
$IntuneFilter = "PartitionKey eq 'IntuneTemplate'"
35-
$RawIntuneTemplates = (Get-CIPPAzDataTableEntity @IntuneTable -Filter $IntuneFilter)
36-
$AllIntuneTemplates = $RawIntuneTemplates | ForEach-Object {
37-
try {
38-
$JSONData = $_.JSON | ConvertFrom-Json -Depth 10 -ErrorAction SilentlyContinue
39-
$data = $JSONData.RAWJson | ConvertFrom-Json -Depth 10 -ErrorAction SilentlyContinue
40-
$data | Add-Member -NotePropertyName 'displayName' -NotePropertyValue $JSONData.Displayname -Force
41-
$data | Add-Member -NotePropertyName 'description' -NotePropertyValue $JSONData.Description -Force
42-
$data | Add-Member -NotePropertyName 'Type' -NotePropertyValue $JSONData.Type -Force
43-
$data | Add-Member -NotePropertyName 'GUID' -NotePropertyValue $_.RowKey -Force
44-
$data
45-
} catch {
46-
# Skip invalid templates
47-
}
48-
} | Sort-Object -Property displayName
4935

36+
if ($IntuneCapable) {
37+
$IntuneFilter = "PartitionKey eq 'IntuneTemplate'"
38+
$RawIntuneTemplates = (Get-CIPPAzDataTableEntity @IntuneTable -Filter $IntuneFilter)
39+
$AllIntuneTemplates = $RawIntuneTemplates | ForEach-Object {
40+
try {
41+
$JSONData = $_.JSON | ConvertFrom-Json -Depth 10 -ErrorAction SilentlyContinue
42+
$data = $JSONData.RAWJson | ConvertFrom-Json -Depth 10 -ErrorAction SilentlyContinue
43+
$data | Add-Member -NotePropertyName 'displayName' -NotePropertyValue $JSONData.Displayname -Force
44+
$data | Add-Member -NotePropertyName 'description' -NotePropertyValue $JSONData.Description -Force
45+
$data | Add-Member -NotePropertyName 'Type' -NotePropertyValue $JSONData.Type -Force
46+
$data | Add-Member -NotePropertyName 'GUID' -NotePropertyValue $_.RowKey -Force
47+
$data
48+
} catch {
49+
# Skip invalid templates
50+
}
51+
} | Sort-Object -Property displayName
52+
}
5053
# Load all CA templates
51-
$CAFilter = "PartitionKey eq 'CATemplate'"
52-
$RawCATemplates = (Get-CIPPAzDataTableEntity @IntuneTable -Filter $CAFilter)
53-
$AllCATemplates = $RawCATemplates | ForEach-Object {
54-
try {
55-
$data = $_.JSON | ConvertFrom-Json -Depth 100 -ErrorAction SilentlyContinue
56-
$data | Add-Member -NotePropertyName 'GUID' -NotePropertyValue $_.RowKey -Force
57-
$data
58-
} catch {
59-
# Skip invalid templates
60-
}
61-
} | Sort-Object -Property displayName
54+
if ($ConditionalAccessCapable) {
55+
$CAFilter = "PartitionKey eq 'CATemplate'"
56+
$RawCATemplates = (Get-CIPPAzDataTableEntity @IntuneTable -Filter $CAFilter)
57+
$AllCATemplates = $RawCATemplates | ForEach-Object {
58+
try {
59+
$data = $_.JSON | ConvertFrom-Json -Depth 100 -ErrorAction SilentlyContinue
60+
$data | Add-Member -NotePropertyName 'GUID' -NotePropertyValue $_.RowKey -Force
61+
$data
62+
} catch {
63+
# Skip invalid templates
64+
}
65+
} | Sort-Object -Property displayName
66+
}
6267

6368
try {
6469
$AlignmentData = Get-CIPPTenantAlignment -TenantFilter $TenantFilter -TemplateId $TemplateId | Where-Object -Property standardType -EQ 'drift'
@@ -136,89 +141,91 @@ function Get-CIPPDrift {
136141
}
137142

138143
# Perform full policy collection
144+
if ($IntuneCapable) {
145+
# Always get live data when not in AllTenants mode
146+
$IntuneRequests = @(
147+
@{
148+
id = 'deviceAppManagement/managedAppPolicies'
149+
url = 'deviceAppManagement/managedAppPolicies'
150+
method = 'GET'
151+
}
152+
@{
153+
id = 'deviceManagement/deviceCompliancePolicies'
154+
url = 'deviceManagement/deviceCompliancePolicies'
155+
method = 'GET'
156+
}
157+
@{
158+
id = 'deviceManagement/groupPolicyConfigurations'
159+
url = 'deviceManagement/groupPolicyConfigurations'
160+
method = 'GET'
161+
}
162+
@{
163+
id = 'deviceManagement/deviceConfigurations'
164+
url = 'deviceManagement/deviceConfigurations'
165+
method = 'GET'
166+
}
167+
@{
168+
id = 'deviceManagement/configurationPolicies'
169+
url = 'deviceManagement/configurationPolicies'
170+
method = 'GET'
171+
}
172+
@{
173+
id = 'deviceManagement/windowsDriverUpdateProfiles'
174+
url = 'deviceManagement/windowsDriverUpdateProfiles'
175+
method = 'GET'
176+
}
177+
@{
178+
id = 'deviceManagement/windowsFeatureUpdateProfiles'
179+
url = 'deviceManagement/windowsFeatureUpdateProfiles'
180+
method = 'GET'
181+
}
182+
@{
183+
id = 'deviceManagement/windowsQualityUpdatePolicies'
184+
url = 'deviceManagement/windowsQualityUpdatePolicies'
185+
method = 'GET'
186+
}
187+
@{
188+
id = 'deviceManagement/windowsQualityUpdateProfiles'
189+
url = 'deviceManagement/windowsQualityUpdateProfiles'
190+
method = 'GET'
191+
}
192+
)
139193

140-
# Always get live data when not in AllTenants mode
141-
$IntuneRequests = @(
142-
@{
143-
id = 'deviceAppManagement/managedAppPolicies'
144-
url = 'deviceAppManagement/managedAppPolicies'
145-
method = 'GET'
146-
}
147-
@{
148-
id = 'deviceManagement/deviceCompliancePolicies'
149-
url = 'deviceManagement/deviceCompliancePolicies'
150-
method = 'GET'
151-
}
152-
@{
153-
id = 'deviceManagement/groupPolicyConfigurations'
154-
url = 'deviceManagement/groupPolicyConfigurations'
155-
method = 'GET'
156-
}
157-
@{
158-
id = 'deviceManagement/deviceConfigurations'
159-
url = 'deviceManagement/deviceConfigurations'
160-
method = 'GET'
161-
}
162-
@{
163-
id = 'deviceManagement/configurationPolicies'
164-
url = 'deviceManagement/configurationPolicies'
165-
method = 'GET'
166-
}
167-
@{
168-
id = 'deviceManagement/windowsDriverUpdateProfiles'
169-
url = 'deviceManagement/windowsDriverUpdateProfiles'
170-
method = 'GET'
171-
}
172-
@{
173-
id = 'deviceManagement/windowsFeatureUpdateProfiles'
174-
url = 'deviceManagement/windowsFeatureUpdateProfiles'
175-
method = 'GET'
176-
}
177-
@{
178-
id = 'deviceManagement/windowsQualityUpdatePolicies'
179-
url = 'deviceManagement/windowsQualityUpdatePolicies'
180-
method = 'GET'
181-
}
182-
@{
183-
id = 'deviceManagement/windowsQualityUpdateProfiles'
184-
url = 'deviceManagement/windowsQualityUpdateProfiles'
185-
method = 'GET'
186-
}
187-
)
188-
189-
$TenantIntunePolicies = [System.Collections.Generic.List[object]]::new()
190-
191-
try {
192-
$IntuneGraphRequest = New-GraphBulkRequest -Requests $IntuneRequests -tenantid $TenantFilter -asapp $true
194+
$TenantIntunePolicies = [System.Collections.Generic.List[object]]::new()
193195

194-
foreach ($Request in $IntuneGraphRequest) {
195-
if ($Request.body.value) {
196-
foreach ($Policy in $Request.body.value) {
197-
$TenantIntunePolicies.Add([PSCustomObject]@{
198-
Type = $Request.id
199-
Policy = $Policy
200-
})
196+
try {
197+
$IntuneGraphRequest = New-GraphBulkRequest -Requests $IntuneRequests -tenantid $TenantFilter -asapp $true
198+
199+
foreach ($Request in $IntuneGraphRequest) {
200+
if ($Request.body.value) {
201+
foreach ($Policy in $Request.body.value) {
202+
$TenantIntunePolicies.Add([PSCustomObject]@{
203+
Type = $Request.id
204+
Policy = $Policy
205+
})
206+
}
201207
}
202208
}
209+
} catch {
210+
Write-Warning "Failed to get Intune policies: $($_.Exception.Message)"
203211
}
204-
} catch {
205-
Write-Warning "Failed to get Intune policies: $($_.Exception.Message)"
206212
}
207-
208213
# Get Conditional Access policies
209-
try {
210-
$CARequests = @(
211-
@{
212-
id = 'policies'
213-
url = 'identity/conditionalAccess/policies'
214-
method = 'GET'
215-
}
216-
)
217-
$CAGraphRequest = New-GraphBulkRequest -Requests $CARequests -tenantid $TenantFilter -asapp $true
218-
$TenantCAPolicies = ($CAGraphRequest | Where-Object { $_.id -eq 'policies' }).body.value
219-
} catch {
220-
Write-Warning "Failed to get Conditional Access policies: $($_.Exception.Message)"
221-
$TenantCAPolicies = @()
214+
if ($ConditionalAccessCapable) {
215+
try {
216+
$CARequests = @(
217+
@{
218+
id = 'policies'
219+
url = 'identity/conditionalAccess/policies'
220+
method = 'GET'
221+
}
222+
)
223+
$CAGraphRequest = New-GraphBulkRequest -Requests $CARequests -tenantid $TenantFilter -asapp $true
224+
$TenantCAPolicies = ($CAGraphRequest | Where-Object { $_.id -eq 'policies' }).body.value
225+
} catch {
226+
Write-Warning "Failed to get Conditional Access policies: $($_.Exception.Message)"
227+
$TenantCAPolicies = @()
228+
}
222229
}
223230

224231
if ($Alignment.standardSettings) {

0 commit comments

Comments
 (0)