Skip to content

Commit

Permalink
Merge pull request #5834 from NikCharlebois/Various-EXO-fixes
Browse files Browse the repository at this point in the history
Various EXO fixes
  • Loading branch information
NikCharlebois authored Feb 24, 2025
2 parents f30b2f7 + 5c1358b commit c4eb342
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 21 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
* Changed the Get-TargetResource logic to return UPN instead of id.
* EXODistributionGroup
* Fixed the ability to set members.
* EXOGroupSettings
* Removed Id from being evaluated in the Test-TargetResource function.
* EXOMailboxAutoReplyConfiguration
* Changed the Get-TargetResource logic to return UPN instead of Identity.
* EXOMailboxCalendarFolder
* Changed the Get-TargetResource logic to return UPN instead of id.
* EXOMailboxPermission
* Changed the Get-TargetResource logic to return UPN instead of id.
* EXOSweepRule
* Changed the Get-TargetResource logic to return UPN instead of id.
* IntuneDeviceComplianceScriptWindows10
* Initial release.
* Security & Compliance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ function Test-TargetResource
Write-Verbose -Message "Current Values: $(Convert-M365DscHashtableToString -Hashtable $CurrentValues)"
Write-Verbose -Message "Target Values: $(Convert-M365DscHashtableToString -Hashtable $PSBoundParameters)"
$ValuesToCheck = $PSBoundParameters
$ValuesToCheck.Remove('Id') | Out-Null
$TestResult = Test-M365DSCParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function Get-TargetResource
{
$ownerValue = Get-User -Identity $config.Identity
$result = @{
Identity = $config.Identity
Identity = $ownerValue.UserPrincipalName
Owner = $ownerValue.UserPrincipalName
AutoDeclineFutureRequestsWhenOOF = [Boolean]$config.AutoDeclineFutureRequestsWhenOOF
AutoReplyState = $config.AutoReplyState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ function Get-TargetResource

try
{
$IdentityParts = $Identity.Split(':')
$userInfo = Get-User -Identity $IdentityParts[0]
$IdentityValue = $userInfo.UserPrincipalName + ":" + $IdentityParts[1]
$folder = Get-MailboxCalendarFolder -Identity $Identity -ErrorAction SilentlyContinue

if ($null -eq $folder)
Expand All @@ -111,7 +114,7 @@ function Get-TargetResource
}

$result = @{
Identity = $folder.Identity
Identity = $IdentityValue
DetailLevel = $folder.DetailLevel
PublishDateRangeFrom = $folder.PublishDateRangeFrom
PublishDateRangeTo = $folder.PublishDateRangeTo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,9 @@ function Get-TargetResource
Ensure = 'Absent'
}

[Array]$permission = Get-MailboxPermission -Identity $Identity -ErrorAction Stop
[Array]$permissions = Get-MailboxPermission -Identity $Identity -ErrorAction Stop

if ($permission.Length -gt 1)
{
$permission = $permission | Where-Object -FilterScript { $_.User -eq $User -and (Compare-Object -ReferenceObject $_.AccessRights.Replace(' ', '').Split(',') -DifferenceObject $AccessRights).Count -eq 0 }
}

if ($permission.Length -gt 1)
{
$permission = $permission[0]
}
$permission = $permissions | Where-Object -FilterScript { $_.User -eq $User -and (Compare-Object -ReferenceObject $_.AccessRights.Replace(' ', '').Split(',') -DifferenceObject $AccessRights).Count -eq 0 }

if ($null -eq $permission)
{
Expand All @@ -117,8 +109,10 @@ function Get-TargetResource
$permission = $Script:exportedInstance
}

$userInfo = Get-User -Identity $permission.Identity

$result = @{
Identity = $permission.Identity
Identity = $userInfo.UserPrincipalName
AccessRights = [Array]$permission.AccessRights.Replace(' ', '').Split(',')
InheritanceType = $permission.InheritanceType
Owner = $permission.Owner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,18 @@ function Get-TargetResource
return $nullResult
}

$userInfo = Get-User -Identity $instance.MailboxOwnerId

$results = @{
Name = $instance.Name
Provider = $instance.Provider
DestinationFolder = $instance.MailboxOwnerId + ':\' + $instance.DestinationFolder
DestinationFolder = $userInfo.UserPrincipalName + ':\' + $instance.DestinationFolder
Enabled = [Boolean]$instance.Enabled
KeepForDays = $instance.KeepForDays
KeepLatest = $instance.KeepLatest
Mailbox = $instance.MailboxOwnerId
Mailbox = $userInfo.UserPrincipalName
SenderName = $instance.Sender.Split('"')[1]
SourceFolder = $instance.MailboxOwnerId + ':\' + $instance.SourceFolder
SourceFolder = $userInfo.UserPrincipalName + ':\' + $instance.SourceFolder
SystemCategory = $instance.SystemCategory
Ensure = 'Present'
Credential = $Credential
Expand Down Expand Up @@ -243,6 +245,7 @@ function Set-TargetResource
Write-Verbose -Message 'Updating existing Sweep Rule.'
$instance = Get-SweepRule -Mailbox $Mailbox | Where-Object -FilterScript { $_.Name -eq $Name }
$SetParameters.Add('Identity', $instance.RuleId)
Write-Verbose -Message "Parameters:`r`n$(ConvertTo-Json $SetParameters -Depth 10)"
Set-SweepRule @SetParameters
}
# REMOVE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function Get-TargetResource
Write-Verbose -Message $Message
return @{
GroupId = $Group.Id
GroupDisplayName = $Group.Displayname
GroupDisplayName = $Group.DisplayName
PolicyType = $GroupPolicyAssignment.PolicyType
PolicyName = $GroupPolicyAssignment.PolicyName
Priority = $GroupPolicyAssignment.Priority
Expand Down Expand Up @@ -443,7 +443,7 @@ function Export-TargetResource
ManagedIdentity = $ManagedIdentity.IsPresent
AccessTokens = $AccessTokens
}
#$results = Get-TargetResource @getParams
#$results = Get-TargetResource @results
$currentDSCBlock = Get-M365DSCExportContentForResource -ResourceName $ResourceName `
-ConnectionMode $ConnectionMode `
-ModulePath $PSScriptRoot `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
UserPrincipalName = "[email protected]"
}
}
Mock -CommandName Get-User -MockWith {
return @{
UserPrincipalName = 'john.smith'
}
}
}

# Test contexts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Remove-MailboxPermission -MockWith {
}

Mock -CommandName Get-User -MockWith {
return @{
UserPrincipalName = 'john.smith'
}
}

# Mock Write-Host to hide output during the tests
Mock -CommandName Write-Host -MockWith {
}
$Script:exportedInstances =$null
$Script:exportedInstance =$null
$Script:ExportMode = $false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
}
}

Mock -CommandName Get-User -MockWith {
return @{
UserPrincipalName = "Test2"
}
}

# Mock Write-Host to hide output during the tests
Mock -CommandName Write-Host -MockWith {
}
Expand Down Expand Up @@ -166,7 +172,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
}

Context -Name "The instance exists and values are NOT in the desired state" -Fixture {

BeforeAll {
$testParams = @{
DestinationFolder = "Deleted Items";
Expand Down Expand Up @@ -194,7 +200,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
}
}
}


It 'Should return Values from the Get method' {
(Get-TargetResource @testParams).Ensure | Should -Be 'Present'
Expand Down

0 comments on commit c4eb342

Please sign in to comment.