From 310ecc24f44d23b93241e95912f24c0113e67a72 Mon Sep 17 00:00:00 2001 From: Vasily Date: Fri, 8 Mar 2024 15:31:11 +0100 Subject: [PATCH 1/5] AADUser --- .../MSFT_AADUser/MSFT_AADUser.psm1 | 123 +++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 index 7f278519cb..17d42ab988 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 @@ -914,7 +914,128 @@ function Export-TargetResource Property = $propertiesToRetrieve ErrorAction = 'Stop' } - if ($Filter -like '*endsWith*') + $queryTypes = @{ + 'eq' = @('assignedPlans/any(a:a/capabilityStatus)', + 'assignedPlans/any(a:a/service)', + 'assignedPlans/any(a:a/servicePlanId)', + 'authorizationInfo/certificateUserIds/any(p:p)', + 'businessPhones/any(p:p)', + 'companyName', + 'createdObjects/any(c:c/id)', + 'employeeHireDate', + 'employeeOrgData/costCenter', + 'employeeOrgData/division', + 'employeeType', + 'faxNumber', + 'mobilePhone', + 'officeLocation', + 'onPremisesExtensionAttributes/extensionAttribute1', + 'onPremisesExtensionAttributes/extensionAttribute10', + 'onPremisesExtensionAttributes/extensionAttribute11', + 'onPremisesExtensionAttributes/extensionAttribute12', + 'onPremisesExtensionAttributes/extensionAttribute13', + 'onPremisesExtensionAttributes/extensionAttribute14', + 'onPremisesExtensionAttributes/extensionAttribute15', + 'onPremisesExtensionAttributes/extensionAttribute2', + 'onPremisesExtensionAttributes/extensionAttribute3', + 'onPremisesExtensionAttributes/extensionAttribute4', + 'onPremisesExtensionAttributes/extensionAttribute5', + 'onPremisesExtensionAttributes/extensionAttribute6', + 'onPremisesExtensionAttributes/extensionAttribute7', + 'onPremisesExtensionAttributes/extensionAttribute8', + 'onPremisesExtensionAttributes/extensionAttribute9', + 'onPremisesSamAccountName', + 'onPremisesSipInfo/isSipEnabled', + 'passwordProfile/forceChangePasswordNextSignIn', + 'passwordProfile/forceChangePasswordNextSignInWithMfa', + 'postalCode', + 'preferredLanguage', + 'provisionedPlans/any(p:p/provisioningStatus)', + 'provisionedPlans/any(p:p/service)', + 'showInAddressList', + 'streetAddress') + + 'startsWith' = @( + 'assignedPlans/any(a:a/service)', + 'businessPhones/any(p:p)', + 'companyName', + 'faxNumber', + 'mobilePhone', + 'officeLocation', + 'onPremisesSamAccountName', + 'postalCode', + 'preferredLanguage', + 'provisionedPlans/any(p:p/service)', + 'streetAddress' + ) + 'ge' = @('employeeHireDate') + 'le' = @('employeeHireDate') + 'eq Null' = @( + 'city', + 'companyName', + 'country', + 'createdDateTime', + 'department', + 'displayName', + 'employeeId', + 'extension_4750531c75d84e8698ecd21bbd5da9f5_fruitPreference', + 'extension_4750531c75d84e8698ecd21bbd5da9f5_test', + 'faxNumber', + 'givenName', + 'jobTitle', + 'mail', + 'mailNickname', + 'mobilePhone', + 'officeLocation', + 'onPremisesExtensionAttributes/extensionAttribute1', + 'onPremisesExtensionAttributes/extensionAttribute10', + 'onPremisesExtensionAttributes/extensionAttribute11', + 'onPremisesExtensionAttributes/extensionAttribute12', + 'onPremisesExtensionAttributes/extensionAttribute13', + 'onPremisesExtensionAttributes/extensionAttribute14', + 'onPremisesExtensionAttributes/extensionAttribute15', + 'onPremisesExtensionAttributes/extensionAttribute2', + 'onPremisesExtensionAttributes/extensionAttribute3', + 'onPremisesExtensionAttributes/extensionAttribute4', + 'onPremisesExtensionAttributes/extensionAttribute5', + 'onPremisesExtensionAttributes/extensionAttribute6', + 'onPremisesExtensionAttributes/extensionAttribute7', + 'onPremisesExtensionAttributes/extensionAttribute8', + 'onPremisesExtensionAttributes/extensionAttribute9', + 'onPremisesSecurityIdentifier', + 'onPremisesSyncEnabled', + 'passwordPolicies', + 'passwordProfile/forceChangePasswordNextSignIn', + 'passwordProfile/forceChangePasswordNextSignInWithMfa', + 'postalCode', + 'preferredLanguage', + 'state', + 'streetAddress', + 'surname', + 'usageLocation', + 'userType' + ) + } + + # Initialize a flag to indicate whether the filter conditions match the attribute support + $allConditionsMatched = $true + + # Check each condition in the filter against the support list + foreach ($condition in $Filter.Split(' ')) + { + if ($condition -match '(\w+)/(\w+):(\w+)') + { + $attribute, $operation, $value = $matches[1], $matches[2], $matches[3] + if (-not $queryTypes.ContainsKey($operation) -or -not $queryTypes[$operation].Contains($attribute)) + { + $allConditionsMatched = $false + break + } + } + } + + # If all conditions match the support, add parameters to $ExportParameters + if ($allConditionsMatched -or $Filter -like '*endsWith*') { $ExportParameters.Add('CountVariable', 'count') $ExportParameters.Add('ConsistencyLevel', 'eventual') From 2a185655d2d48f2d0fe8a8391a649e53f2802ef6 Mon Sep 17 00:00:00 2001 From: Vasily Date: Sun, 10 Mar 2024 08:53:28 +0100 Subject: [PATCH 2/5] update filters for mguser --- .../DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 | 3 --- 1 file changed, 3 deletions(-) diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 index 17d42ab988..9d8f0068f5 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 @@ -945,7 +945,6 @@ function Export-TargetResource 'onPremisesExtensionAttributes/extensionAttribute8', 'onPremisesExtensionAttributes/extensionAttribute9', 'onPremisesSamAccountName', - 'onPremisesSipInfo/isSipEnabled', 'passwordProfile/forceChangePasswordNextSignIn', 'passwordProfile/forceChangePasswordNextSignInWithMfa', 'postalCode', @@ -978,8 +977,6 @@ function Export-TargetResource 'department', 'displayName', 'employeeId', - 'extension_4750531c75d84e8698ecd21bbd5da9f5_fruitPreference', - 'extension_4750531c75d84e8698ecd21bbd5da9f5_test', 'faxNumber', 'givenName', 'jobTitle', From 4836cec1c8e8fb0cf2269ab182cd82e8a5b7657e Mon Sep 17 00:00:00 2001 From: Vasily Date: Mon, 18 Mar 2024 17:17:42 +0100 Subject: [PATCH 3/5] Update MSFT_AADUser.psm1 check if $Filter is null implemented --- .../MSFT_AADUser/MSFT_AADUser.psm1 | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 index 9d8f0068f5..678a6f619a 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 @@ -1018,19 +1018,25 @@ function Export-TargetResource $allConditionsMatched = $true # Check each condition in the filter against the support list - foreach ($condition in $Filter.Split(' ')) - { - if ($condition -match '(\w+)/(\w+):(\w+)') - { - $attribute, $operation, $value = $matches[1], $matches[2], $matches[3] - if (-not $queryTypes.ContainsKey($operation) -or -not $queryTypes[$operation].Contains($attribute)) - { - $allConditionsMatched = $false - break + # Assuming the provided PowerShell script is part of a larger context and the variable $Filter is defined elsewhere + + # Check if $Filter is not null + if ($Filter) { + # Check each condition in the filter against the support list + foreach ($condition in $Filter.Split(' ')) { + if ($condition -match '(\w+)/(\w+):(\w+)') { + $attribute, $operation, $value = $matches[1], $matches[2], $matches[3] + if (-not $queryTypes.ContainsKey($operation) -or -not $queryTypes[$operation].Contains($attribute)) { + $allConditionsMatched = $false + break + } } } + } else { + Write-Host "$Filter is null or empty." } + # If all conditions match the support, add parameters to $ExportParameters if ($allConditionsMatched -or $Filter -like '*endsWith*') { From afacaf0a76fc5d1365aff583e2912ba1ce403a4b Mon Sep 17 00:00:00 2001 From: Vasily Date: Wed, 3 Apr 2024 15:22:47 +0200 Subject: [PATCH 4/5] Removed printing "Filter is null" on export with a Write-Host --- .../Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 index 678a6f619a..cefb42685c 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 @@ -1032,8 +1032,6 @@ function Export-TargetResource } } } - } else { - Write-Host "$Filter is null or empty." } From 10d6a64a3ed7bc96679119645db3b682a6605781 Mon Sep 17 00:00:00 2001 From: Vasily Date: Wed, 3 Apr 2024 15:40:26 +0200 Subject: [PATCH 5/5] Update MSFT_AADUser.psm1 Code styling --- .../Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 | 1 - 1 file changed, 1 deletion(-) diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 index cefb42685c..b1f10043a2 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 @@ -1034,7 +1034,6 @@ function Export-TargetResource } } - # If all conditions match the support, add parameters to $ExportParameters if ($allConditionsMatched -or $Filter -like '*endsWith*') {