Skip to content

Commit 68157ec

Browse files
authored
Merge pull request #510 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 1e361e8 + 3061a75 commit 68157ec

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Modules/CIPPCore/Public/TenantGroups/Get-TenantGroups.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function Get-TenantGroups {
8989
Description = $Group.Description
9090
GroupType = $Group.GroupType ?? 'static'
9191
RuleLogic = $Group.RuleLogic ?? 'and'
92-
DynamicRules = $Group.DynamicRules ? ( $(@($Group.DynamicRules | ConvertFrom-Json)) ) : @()
92+
DynamicRules = $Group.DynamicRules ? @($Group.DynamicRules | ConvertFrom-Json) : @()
9393
Members = @($SortedMembers)
9494
})
9595
}

Modules/CIPPCore/Public/TenantGroups/Update-CIPPDynamicTenantGroups.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function Update-CIPPDynamicTenantGroups {
3737
foreach ($Group in $DynamicGroups) {
3838
try {
3939
Write-LogMessage -API 'TenantGroups' -message "Processing dynamic group: $($Group.Name)" -sev Info
40-
$Rules = $Group.DynamicRules | ConvertFrom-Json
40+
$Rules = @($Group.DynamicRules | ConvertFrom-Json)
4141
# Build a single Where-Object string for AND logic
4242
$WhereConditions = foreach ($Rule in $Rules) {
4343
$Property = $Rule.property
@@ -74,8 +74,10 @@ function Update-CIPPDynamicTenantGroups {
7474

7575
}
7676
$TenantObj = $AllTenants | ForEach-Object {
77-
$LicenseInfo = New-GraphGetRequest -uri 'https://graph.microsoft.com/v1.0/subscribedSkus' -TenantId $_.defaultDomainName
78-
$SKUId = $LicenseInfo.SKUId
77+
if ($Rules.property -contains 'availableLicense') {
78+
$LicenseInfo = New-GraphGetRequest -uri 'https://graph.microsoft.com/v1.0/subscribedSkus' -TenantId $_.defaultDomainName
79+
}
80+
$SKUId = $LicenseInfo.SKUId ?? @()
7981
$ServicePlans = (Get-CIPPTenantCapabilities -TenantFilter $_.defaultDomainName).psobject.properties.name
8082
[pscustomobject]@{
8183
customerId = $_.customerId
@@ -89,9 +91,13 @@ function Update-CIPPDynamicTenantGroups {
8991
# Combine all conditions with the specified logic (AND or OR)
9092
$LogicOperator = if ($Group.RuleLogic -eq 'or') { ' -or ' } else { ' -and ' }
9193
$WhereString = $WhereConditions -join $LogicOperator
94+
Write-Information "Evaluating tenants with condition: $WhereString"
95+
9296
$ScriptBlock = [ScriptBlock]::Create($WhereString)
9397
$MatchingTenants = $TenantObj | Where-Object $ScriptBlock
9498

99+
Write-Information "Found $($MatchingTenants.Count) matching tenants for group '$($Group.Name)'"
100+
95101
$CurrentMembers = Get-CIPPAzDataTableEntity @MembersTable -Filter "PartitionKey eq 'Member' and GroupId eq '$($Group.RowKey)'"
96102
$CurrentMemberIds = $CurrentMembers.customerId
97103
$NewMemberIds = $MatchingTenants.customerId

0 commit comments

Comments
 (0)