From 11453ab48ea6ff504a1c6d4c9bb63faad65b35aa Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Tue, 14 Nov 2023 16:24:06 -0800 Subject: [PATCH] Fixes #3900 --- CHANGELOG.md | 7 +++ .../MSFT_EXOCASMailboxPlan.psm1 | 53 ++++++++++--------- .../MSFT_EXOMailboxPlan.psm1 | 2 +- 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2af87cc081..b5a9ae207f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change log for Microsoft365DSC +# UNRELEASED + +* EXOCASMailboxPlan + * Fixes an issue where we are not able to set the settings of a CAS + Mailbox Plan by specifying the Identity without the GUID in the name. + FIXES [#3900](https://github.com/microsoft/Microsoft365DSC/issues/3900) + # 1.23.1108.3 * AADRoleEligibilityScheduleRequest diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOCASMailboxPlan/MSFT_EXOCASMailboxPlan.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOCASMailboxPlan/MSFT_EXOCASMailboxPlan.psm1 index 1220beca92..6871b84c96 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOCASMailboxPlan/MSFT_EXOCASMailboxPlan.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOCASMailboxPlan/MSFT_EXOCASMailboxPlan.psm1 @@ -91,33 +91,36 @@ function Get-TargetResource try { $CASMailboxPlan = Get-CASMailboxPlan -Identity $Identity -ErrorAction Stop - - if ($null -eq $CASMailboxPlan) - { - Write-Verbose -Message "CASMailboxPlan $($Identity) does not exist." - return $nullResult - } - else + if ($null -eq $MailboxPlan) { - $result = @{ - Identity = $Identity - ActiveSyncEnabled = $CASMailboxPlan.ActiveSyncEnabled - ImapEnabled = $CASMailboxPlan.ImapEnabled - OwaMailboxPolicy = $CASMailboxPlan.OwaMailboxPolicy - PopEnabled = $CASMailboxPlan.PopEnabled - Credential = $Credential - ApplicationId = $ApplicationId - CertificateThumbprint = $CertificateThumbprint - CertificatePath = $CertificatePath - CertificatePassword = $CertificatePassword - Managedidentity = $ManagedIdentity.IsPresent - TenantId = $TenantId + Write-Verbose -Message "MailboxPlan $($Identity) does not exist." + + $CASMailboxPlan = Get-CASMailboxPlan -Filter "Name -like '$($Identity.Split('-')[0])*'" + if ($null -eq $CASMailboxPlan) + { + Write-Verbose -Message "CASMailboxPlan $($Identity) does not exist." + return $nullResult } + } - Write-Verbose -Message "Found CASMailboxPlan $($Identity)" - Write-Verbose -Message "Get-TargetResource Result: `n $(Convert-M365DscHashtableToString -Hashtable $result)" - return $result + $result = @{ + Identity = $Identity + ActiveSyncEnabled = $CASMailboxPlan.ActiveSyncEnabled + ImapEnabled = $CASMailboxPlan.ImapEnabled + OwaMailboxPolicy = $CASMailboxPlan.OwaMailboxPolicy + PopEnabled = $CASMailboxPlan.PopEnabled + Credential = $Credential + ApplicationId = $ApplicationId + CertificateThumbprint = $CertificateThumbprint + CertificatePath = $CertificatePath + CertificatePassword = $CertificatePassword + Managedidentity = $ManagedIdentity.IsPresent + TenantId = $TenantId } + + Write-Verbose -Message "Found CASMailboxPlan $($Identity)" + Write-Verbose -Message "Get-TargetResource Result: `n $(Convert-M365DscHashtableToString -Hashtable $result)" + return $result } catch { @@ -217,11 +220,11 @@ function Set-TargetResource $CASMailboxPlanParams.Remove('CertificatePassword') | Out-Null $CASMailboxPlanParams.Remove('ManagedIdentity') | Out-Null - $CASMailboxPlans = Get-CASMailboxPlan - $CASMailboxPlan = $CASMailboxPlans | Where-Object -FilterScript { $_.Identity -eq $Identity } + $CASMailboxPlan = Get-CASMailboxPlan -Filter "Name -like '$Identity*'" if ($null -ne $CASMailboxPlan) { + $CasMailboxPlanParams.Identity = $CASMailboxPlan.Identity Write-Verbose -Message "Setting CASMailboxPlan $Identity with values: $(Convert-M365DscHashtableToString -Hashtable $CASMailboxPlanParams)" Set-CASMailboxPlan @CASMailboxPlanParams } diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOMailboxPlan/MSFT_EXOMailboxPlan.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOMailboxPlan/MSFT_EXOMailboxPlan.psm1 index aae6a4a598..9c2fbb2a62 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOMailboxPlan/MSFT_EXOMailboxPlan.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOMailboxPlan/MSFT_EXOMailboxPlan.psm1 @@ -112,7 +112,7 @@ function Get-TargetResource { Write-Verbose -Message "MailboxPlan $($Identity) does not exist." - $MailboxPlan = Get-MailboxPlan -Filter "Name like '$($Identity.Split('-')[0])*'" + $MailboxPlan = Get-MailboxPlan -Filter "Name -like '$($Identity.Split('-')[0])*'" if ($null -eq $MailboxPlan) { return $nullResult