Skip to content

Commit 9267652

Browse files
committed
Update Register-CippExtensionScheduledTasks.ps1
1 parent d585ae2 commit 9267652

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

Modules/CippExtensions/Public/Extension Functions/Register-CippExtensionScheduledTasks.ps1

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,25 @@ function Register-CIPPExtensionScheduledTasks {
2020
$ExtensionConfig = $Config.$Extension
2121
if ($ExtensionConfig.Enabled -eq $true -or $Extension -eq 'CustomData') {
2222
if ($Extension -eq 'CustomData') {
23-
$CustomDataMappingTable = Get-CIPPTable -TableName CustomDataMapping
23+
$CustomDataMappingTable = Get-CIPPTable -TableName CustomDataMappings
2424
$Mappings = Get-CIPPAzDataTableEntity @CustomDataMappingTable | ForEach-Object {
2525
$Mapping = $_.JSON | ConvertFrom-Json
26-
[pscustomobject]@{
27-
RowKey = $Mapping.tenantFilter.value
26+
27+
$TenantMappings = if ($Mapping.tenantFilter.value -eq 'AllTenants') {
28+
$Tenants
29+
} else {
30+
$Tenants | Where-Object { $_.customerId -eq $Mapping.tenantFilter.value -or $_.defaultDomainName -eq $Mapping.tenantFilter.value }
31+
}
32+
foreach ($TenantMapping in $TenantMappings) {
33+
[pscustomobject]@{
34+
RowKey = $TenantMapping.customerId
35+
}
2836
}
37+
} | Sort-Object -Property RowKey -Unique
38+
39+
if (($Mappings | Measure-Object).Count -eq 0) {
40+
Write-Warning 'No tenants found for CustomData extension'
41+
continue
2942
}
3043
} else {
3144
$Mappings = Get-CIPPAzDataTableEntity @MappingsTable -Filter "PartitionKey eq '$($Extension)Mapping'"
@@ -45,7 +58,7 @@ function Register-CIPPExtensionScheduledTasks {
4558
$SyncTypes.Add('Devices')
4659

4760
foreach ($Mapping in $Mappings) {
48-
$Tenant = $Tenants | Where-Object { $_.customerId -eq $Mapping.RowKey -or $_.defaultDomainName -eq $Mapping.RowKey -or $Mapping.RowKey -eq 'AllTenants' }
61+
$Tenant = $Tenants | Where-Object { $_.customerId -eq $Mapping.RowKey }
4962
if (!$Tenant) {
5063
Write-Warning "Tenant $($Mapping.RowKey) not found"
5164
continue

0 commit comments

Comments
 (0)