Skip to content

Commit

Permalink
Merge pull request #5309 from NikCharlebois/EXOMailboxSettings
Browse files Browse the repository at this point in the history
EXOMailboxSettings Improvements
  • Loading branch information
NikCharlebois authored Oct 31, 2024
2 parents d177178 + 770ff51 commit 8aa9af7
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
* Initial Release
* EXOMailboxAuditBypassAssociation
* Initial release.
* EXOMailboxSettings
* Added support for AddressBookPolicy, RetentionPolicy, RoleAssignmentPolicy
and SharingPolicy.
* EXOServicePrincipal
* Initial release.
* EXOTenantAllowBlockListItems
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ function Get-TargetResource
[System.String]
$Locale,

[Parameter()]
[System.String]
$RetentionPolicy,

[Parameter()]
[System.String]
$AddressBookPolicy,

[Parameter()]
[System.String]
$RoleAssignmentPolicy,

[Parameter()]
[System.String]
$SharingPolicy,

[Parameter()]
[ValidateSet('Present')]
[System.String]
Expand Down Expand Up @@ -87,6 +103,7 @@ function Get-TargetResource
try
{
$mailboxSettings = Get-MailboxRegionalConfiguration -Identity $DisplayName -ErrorAction Stop
$mailboxInfo = Get-Mailbox -Identity $DisplayName -ErrorAction Stop
}
catch
{
Expand All @@ -103,6 +120,11 @@ function Get-TargetResource
DisplayName = $DisplayName
TimeZone = $mailboxSettings.TimeZone
Locale = $mailboxSettings.Language.Name
RetentionPolicy = $mailboxInfo.RetentionPolicy
AddressBookPolicy = $mailboxInfo.AddressBookPolicy
RoleAssignmentPolicy = $mailboxInfo.RoleAssignmentPolicy
SharingPolicy = $mailboxInfo.SharingPolicy
Ensure = "Present"
Credential = $Credential
ApplicationId = $ApplicationId
CertificateThumbprint = $CertificateThumbprint
Expand Down Expand Up @@ -134,6 +156,22 @@ function Set-TargetResource
[System.String]
$Locale,

[Parameter()]
[System.String]
$RetentionPolicy,

[Parameter()]
[System.String]
$AddressBookPolicy,

[Parameter()]
[System.String]
$RoleAssignmentPolicy,

[Parameter()]
[System.String]
$SharingPolicy,

[Parameter()]
[ValidateSet('Present')]
[System.String]
Expand Down Expand Up @@ -191,6 +229,36 @@ function Set-TargetResource
Set-MailboxRegionalConfiguration -Identity $DisplayName `
-Language $Locale `
-TimeZone $TimeZone

$needToUpdate = $false
$updateParams = @{
Identity = $DisplayName
}
if (-not [System.String]::IsNullOrEmpty($AddressBookPolicy))
{
$needToUpdate = $true
$updateParams.Add('AddressBookPolicy', $AddressBookPolicy)
}
if (-not [System.String]::IsNullOrEmpty($RoleAssignmentPolicy))
{
$needToUpdate = $true
$updateParams.Add('RoleAssignmentPolicy', $RoleAssignmentPolicy)
}
if (-not [System.String]::IsNullOrEmpty($RetentionPolicy))
{
$needToUpdate = $true
$updateParams.Add('RetentionPolicy', $RetentionPolicy)
}
if (-not [System.String]::IsNullOrEmpty($SharingPolicy))
{
$needToUpdate = $true
$updateParams.Add('SharingPolicy', $SharingPolicy)
}
if ($needToUpdate)
{
Write-Verbose -Message "Updating Mailbox specific properties with:`r`n$(Convert-M365DscHashtableToString -Hashtable $updateParams)"
Set-Mailbox @updateParams
}
}

function Test-TargetResource
Expand All @@ -211,6 +279,22 @@ function Test-TargetResource
[System.String]
$Locale,

[Parameter()]
[System.String]
$RetentionPolicy,

[Parameter()]
[System.String]
$AddressBookPolicy,

[Parameter()]
[System.String]
$RoleAssignmentPolicy,

[Parameter()]
[System.String]
$SharingPolicy,

[Parameter()]
[ValidateSet('Present')]
[System.String]
Expand Down Expand Up @@ -264,19 +348,20 @@ function Test-TargetResource

$CurrentValues = Get-TargetResource @PSBoundParameters

$CurrentValues = Get-TargetResource @PSBoundParameters
$ValuesToCheck = ([Hashtable]$PSBoundParameters).Clone()

Write-Verbose -Message "Current Values: $(Convert-M365DscHashtableToString -Hashtable $CurrentValues)"
Write-Verbose -Message "Target Values: $(Convert-M365DscHashtableToString -Hashtable $PSBoundParameters)"

$TestResult = Test-M365DSCParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @('DisplayName', `
'TimeZone', `
'Locale')
$testResult = Test-M365DSCParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck $ValuesToCheck.Keys

Write-Verbose -Message "Test-TargetResource returned $TestResult"
Write-Verbose -Message "Test-TargetResource returned $testResult"

return $TestResult
return $testResult
}

function Export-TargetResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
class MSFT_EXOMailboxSettings : OMI_BaseResource
{
[Key, Description("The display name of the Shared Mailbox")] string DisplayName;
[Write, Description("Associated retention policy.")] string RetentionPolicy;
[Write, Description("Associated address book policy.")] string AddressBookPolicy;
[Write, Description("Associated role assignment policy.")] string RoleAssignmentPolicy;
[Write, Description("Associated sharing policy.")] string SharingPolicy;
[Write, Description("The name of the Time Zone to assign to the mailbox")] string TimeZone;
[Write, Description("The code of the Locale to assign to the mailbox")] string Locale;
[Write, Description("Present ensures the Mailbox Settings are applied"), ValueMap{"Present"}, Values{"Present"}] string Ensure;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
return 'Credentials'
}

Mock -CommandName Set-Mailbox -MockWith {}

# Mock Write-Host to hide output during the tests
Mock -CommandName Write-Host -MockWith {
}
Expand Down

0 comments on commit 8aa9af7

Please sign in to comment.