Skip to content

Commit 5006b66

Browse files
authored
Merge pull request #652 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 4341acd + 7fbadce commit 5006b66

File tree

8 files changed

+105
-8
lines changed

8 files changed

+105
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ ExcludedTenants
1010
SendNotifications/config.json
1111
.env
1212
Output/
13+
node_modules/.yarn-integrity
14+
yarn.lock
1315

1416
# Cursor IDE
1517
.cursor/rules

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-CIPPDBCacheData.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,16 @@ function Push-CIPPDBCacheData {
210210
try { Set-CIPPDBCacheExoAcceptedDomains -TenantFilter $TenantFilter } catch {
211211
Write-LogMessage -API 'CIPPDBCache' -tenant $TenantFilter -message "ExoAcceptedDomains collection failed: $($_.Exception.Message)" -sev Error
212212
}
213+
214+
Write-Host 'Getting cache for License Overview'
215+
try { Set-CIPPDBCacheLicenseOverview -TenantFilter $TenantFilter } catch {
216+
Write-LogMessage -API 'CIPPDBCache' -tenant $TenantFilter -message "License Overview collection failed: $($_.Exception.Message)" -sev Error
217+
}
218+
219+
Write-Host 'Getting cache for MFA State'
220+
try { Set-CIPPDBCacheMFAState -TenantFilter $TenantFilter } catch {
221+
Write-LogMessage -API 'CIPPDBCache' -tenant $TenantFilter -message "MFA State collection failed: $($_.Exception.Message)" -sev Error
222+
}
213223
#endregion All Licenses
214224

215225
#region Conditional Access Licensed - Azure AD Premium features

Modules/CIPPCore/Public/New-CIPPCAPolicy.ps1

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,26 @@ function New-CIPPCAPolicy {
173173
if (!$location.displayName) { continue }
174174
$CheckExisting = New-GraphGETRequest -uri 'https://graph.microsoft.com/beta/identity/conditionalAccess/namedLocations' -tenantid $TenantFilter -asApp $true
175175
if ($Location.displayName -in $CheckExisting.displayName) {
176+
$ExistingLocation = $CheckExisting | Where-Object -Property displayName -EQ $Location.displayName
177+
if ($Overwrite) {
178+
$LocationUpdate = $location | Select-Object * -ExcludeProperty id
179+
Remove-ODataProperties -Object $LocationUpdate
180+
$Body = ConvertTo-Json -InputObject $LocationUpdate -Depth 10
181+
try {
182+
$null = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/identity/conditionalAccess/namedLocations/$($ExistingLocation.id)" -body $body -Type PATCH -tenantid $tenantfilter -asApp $true
183+
Write-LogMessage -Tenant $TenantFilter -Headers $User -API $APINAME -message "Updated existing Named Location: $($location.displayName)" -Sev 'Info'
184+
} catch {
185+
Write-Warning "Failed to update location $($location.displayName): $_"
186+
Write-LogMessage -Tenant $TenantFilter -Headers $User -API $APINAME -message "Failed to update existing Named Location: $($location.displayName). Error: $_" -Sev 'Error'
187+
}
188+
} else {
189+
Write-LogMessage -Tenant $TenantFilter -Headers $User -API $APINAME -message "Matched a CA policy with the existing Named Location: $($location.displayName)" -Sev 'Info'
190+
}
176191
[pscustomobject]@{
177-
id = ($CheckExisting | Where-Object -Property displayName -EQ $Location.displayName).id
178-
name = ($CheckExisting | Where-Object -Property displayName -EQ $Location.displayName).displayName
179-
templateId = $location.id
192+
id = $ExistingLocation.id
193+
name = $ExistingLocation.displayName
194+
templateId = $location.id
180195
}
181-
Write-LogMessage -Tenant $TenantFilter -Headers $User -API $APINAME -message "Matched a CA policy with the existing Named Location: $($location.displayName)" -Sev 'Info'
182-
183196
} else {
184197
if ($location.countriesAndRegions) { $location.countriesAndRegions = @($location.countriesAndRegions) }
185198
$location | Select-Object * -ExcludeProperty id
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function Set-CIPPDBCacheLicenseOverview {
2+
<#
3+
.SYNOPSIS
4+
Caches license overview for a tenant
5+
6+
.PARAMETER TenantFilter
7+
The tenant to cache license overview for
8+
#>
9+
[CmdletBinding()]
10+
param(
11+
[Parameter(Mandatory = $true)]
12+
[string]$TenantFilter
13+
)
14+
15+
try {
16+
Write-LogMessage -API 'CIPPDBCache' -tenant $TenantFilter -message 'Caching license overview' -sev Info
17+
18+
$LicenseOverview = Get-CIPPLicenseOverview -TenantFilter $TenantFilter
19+
Add-CIPPDbItem -TenantFilter $TenantFilter -Type 'LicenseOverview' -Data @($LicenseOverview)
20+
$LicenseOverview = $null
21+
22+
Write-LogMessage -API 'CIPPDBCache' -tenant $TenantFilter -message 'Cached license overview successfully' -sev Info
23+
24+
} catch {
25+
Write-LogMessage -API 'CIPPDBCache' -tenant $TenantFilter -message "Failed to cache license overview: $($_.Exception.Message)" -sev Error
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function Set-CIPPDBCacheMFAState {
2+
<#
3+
.SYNOPSIS
4+
Caches MFA state for a tenant
5+
6+
.PARAMETER TenantFilter
7+
The tenant to cache MFA state for
8+
#>
9+
[CmdletBinding()]
10+
param(
11+
[Parameter(Mandatory = $true)]
12+
[string]$TenantFilter
13+
)
14+
15+
try {
16+
Write-LogMessage -API 'CIPPDBCache' -tenant $TenantFilter -message 'Caching MFA state' -sev Info
17+
18+
$MFAState = Get-CIPPMFAState -TenantFilter $TenantFilter
19+
Add-CIPPDbItem -TenantFilter $TenantFilter -Type 'MFAState' -Data @($MFAState)
20+
$MFAState = $null
21+
22+
Write-LogMessage -API 'CIPPDBCache' -tenant $TenantFilter -message 'Cached MFA state successfully' -sev Info
23+
24+
} catch {
25+
Write-LogMessage -API 'CIPPDBCache' -tenant $TenantFilter -message "Failed to cache MFA state: $($_.Exception.Message)" -sev Error
26+
}
27+
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,13 @@ function Invoke-CIPPStandardTransportRuleTemplate {
4949
try {
5050
if ($Existing) {
5151
Write-Host 'Found existing'
52-
$RequestParams | Add-Member -NotePropertyValue $RequestParams.name -NotePropertyName Identity
53-
$GraphRequest = New-ExoRequest -tenantid $Tenant -cmdlet 'Set-TransportRule' -cmdParams ($RequestParams | Select-Object -Property * -ExcludeProperty GUID, Comments, HasSenderOverride, ExceptIfHasSenderOverride, ExceptIfMessageContainsDataClassifications, MessageContainsDataClassifications, UseLegacyRegex) -useSystemMailbox $true
54-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Successfully set transport rule for $tenant" -sev 'Info'
52+
if ($Settings.overwrite) {
53+
$RequestParams | Add-Member -NotePropertyValue $RequestParams.name -NotePropertyName Identity
54+
$GraphRequest = New-ExoRequest -tenantid $Tenant -cmdlet 'Set-TransportRule' -cmdParams ($RequestParams | Select-Object -Property * -ExcludeProperty GUID, Comments, HasSenderOverride, ExceptIfHasSenderOverride, ExceptIfMessageContainsDataClassifications, MessageContainsDataClassifications, UseLegacyRegex) -useSystemMailbox $true
55+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Successfully set transport rule for $tenant" -sev 'Info'
56+
} else {
57+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Skipping transport rule for $tenant as it already exists" -sev 'Info'
58+
}
5559
} else {
5660
Write-Host 'Creating new'
5761
$GraphRequest = New-ExoRequest -tenantid $Tenant -cmdlet 'New-TransportRule' -cmdParams ($RequestParams | Select-Object -Property * -ExcludeProperty GUID, Comments, HasSenderOverride, ExceptIfHasSenderOverride, ExceptIfMessageContainsDataClassifications, MessageContainsDataClassifications, UseLegacyRegex) -useSystemMailbox $true

node_modules/.yarn-integrity

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+

0 commit comments

Comments
 (0)