@@ -52,18 +52,28 @@ function Update-CIPPDynamicTenantGroups {
5252 if ($Operator -in @ (' in' , ' notin' )) {
5353 $arrayValues = if ($Value -is [array ]) { $Value.guid } else { @ ($Value.guid ) }
5454 $arrayAsString = $arrayValues | ForEach-Object { " '$_ '" }
55- " (`$ _.skuId | Where-Object { `$ _ -in @($ ( $arrayAsString -join ' , ' ) ) }).Count -gt 0"
55+ if ($Operator -eq ' in' ) {
56+ " (`$ _.skuId | Where-Object { `$ _ -in @($ ( $arrayAsString -join ' , ' ) ) }).Count -gt 0"
57+ } else {
58+ " (`$ _.skuId | Where-Object { `$ _ -in @($ ( $arrayAsString -join ' , ' ) ) }).Count -eq 0"
59+ }
5660 } else {
57- " `$ _.skuId -contains '$ ( $Value.guid ) '"
61+ " `$ _.skuId -$Operator '$ ( $Value.guid ) '"
5862 }
5963 }
6064 ' availableServicePlan' {
6165 if ($Operator -in @ (' in' , ' notin' )) {
6266 $arrayValues = if ($Value -is [array ]) { $Value.value } else { @ ($Value.value ) }
6367 $arrayAsString = $arrayValues | ForEach-Object { " '$_ '" }
64- " (`$ _.servicePlans | Where-Object { `$ _ -in @($ ( $arrayAsString -join ' , ' ) ) }).Count -gt 0"
68+ if ($Operator -eq ' in' ) {
69+ # Keep tenants with ANY of the provided plans
70+ " (`$ _.servicePlans | Where-Object { `$ _ -in @($ ( $arrayAsString -join ' , ' ) ) }).Count -gt 0"
71+ } else {
72+ # Exclude tenants with ANY of the provided plans
73+ " (`$ _.servicePlans | Where-Object { `$ _ -in @($ ( $arrayAsString -join ' , ' ) ) }).Count -eq 0"
74+ }
6575 } else {
66- " `$ _.servicePlans -contains '$ ( $Value.value ) '"
76+ " `$ _.servicePlans -$Operator '$ ( $Value.value ) '"
6777 }
6878 }
6979 default {
@@ -73,6 +83,9 @@ function Update-CIPPDynamicTenantGroups {
7383 }
7484
7585 }
86+ if (! $WhereConditions ) {
87+ throw ' Generating the conditions failed. The conditions seem to be empty.'
88+ }
7689 $TenantObj = $AllTenants | ForEach-Object {
7790 if ($Rules.property -contains ' availableLicense' ) {
7891 $LicenseInfo = New-GraphGetRequest - uri ' https://graph.microsoft.com/v1.0/subscribedSkus' - TenantId $_.defaultDomainName
0 commit comments