Skip to content

Commit bcf23e1

Browse files
committed
add license checks for risk based conditions
1 parent e9ded06 commit bcf23e1

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardConditionalAccessTemplate.ps1

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function Invoke-CIPPStandardConditionalAccessTemplate {
3232
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'ConditionalAccess'
3333
$Table = Get-CippTable -tablename 'templates'
3434
$TestResult = Test-CIPPStandardLicense -StandardName 'ConditionalAccessTemplate_general' -TenantFilter $Tenant -RequiredCapabilities @('AAD_PREMIUM', 'AAD_PREMIUM_P2')
35+
$TestP2 = Test-CIPPStandardLicense -StandardName 'ConditionalAccessTemplate_p2' -TenantFilter $Tenant -RequiredCapabilities @('AAD_PREMIUM_P2')
3536
if ($TestResult -eq $false) {
3637
#writing to each item that the license is not present.
3738
$settings.TemplateList | ForEach-Object {
@@ -42,9 +43,8 @@ function Invoke-CIPPStandardConditionalAccessTemplate {
4243
} #we're done.
4344

4445
try {
45-
$AllCAPolicies = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/identity/conditionalAccess/policies?$top=999' -tenantid $Tenant
46-
}
47-
catch {
46+
$AllCAPolicies = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/identity/conditionalAccess/policies?$top=999' -tenantid $Tenant -asApp $true
47+
} catch {
4848
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
4949
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Could not get the ConditionalAccessTemplate state for $Tenant. Error: $ErrorMessage" -Sev Error
5050
return
@@ -55,6 +55,13 @@ function Invoke-CIPPStandardConditionalAccessTemplate {
5555
try {
5656
$Filter = "PartitionKey eq 'CATemplate' and RowKey eq '$($Setting.TemplateList.value)'"
5757
$JSONObj = (Get-CippAzDataTableEntity @Table -Filter $Filter).JSON
58+
$Policy = $JSONObj | ConvertFrom-Json
59+
if ($Policy.conditions.userRiskLevels.count -gt 0 -or $Policy.conditions.signInRiskLevels.count -gt 0) {
60+
if (!$TestP2) {
61+
Write-Information "Skipping policy $($Policy.displayName) as it requires AAD Premium P2 license."
62+
continue
63+
}
64+
}
5865
$null = New-CIPPCAPolicy -replacePattern 'displayName' -TenantFilter $tenant -state $Setting.state -RawJSON $JSONObj -Overwrite $true -APIName $APIName -Headers $Request.Headers -DisableSD $Setting.DisableSD
5966
} catch {
6067
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
@@ -70,7 +77,15 @@ function Invoke-CIPPStandardConditionalAccessTemplate {
7077
$policy = $Policies | Where-Object { $_.displayName -eq $Setting.label }
7178
$CheckExististing = $AllCAPolicies | Where-Object -Property displayName -EQ $Setting.label
7279
if (!$CheckExististing) {
73-
Set-CIPPStandardsCompareField -FieldName "standards.ConditionalAccessTemplate.$($Setting.value)" -FieldValue "Policy $($Setting.label) is missing from this tenant." -Tenant $Tenant
80+
if ($Setting.conditions.userRiskLevels.Count -gt 0 -or $Setting.conditions.signInRiskLevels.Count -gt 0) {
81+
if (!$TestP2) {
82+
Set-CIPPStandardsCompareField -FieldName "standards.ConditionalAccessTemplate.$($Setting.value)" -FieldValue "Policy $($Setting.label) requires AAD Premium P2 license." -Tenant $Tenant
83+
} else {
84+
Set-CIPPStandardsCompareField -FieldName "standards.ConditionalAccessTemplate.$($Setting.value)" -FieldValue "Policy $($Setting.label) is missing from this tenant." -Tenant $Tenant
85+
}
86+
} else {
87+
Set-CIPPStandardsCompareField -FieldName "standards.ConditionalAccessTemplate.$($Setting.value)" -FieldValue "Policy $($Setting.label) is missing from this tenant." -Tenant $Tenant
88+
}
7489
} else {
7590
$CompareObj = ConvertFrom-Json -ErrorAction SilentlyContinue -InputObject (New-CIPPCATemplate -TenantFilter $tenant -JSON $CheckExististing)
7691
$Compare = Compare-CIPPIntuneObject -ReferenceObject $policy -DifferenceObject $CompareObj

0 commit comments

Comments
 (0)