diff --git a/CHANGELOG.md b/CHANGELOG.md index dbca59ee92..0d2b3cca7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ # Change log for Microsoft365DSC # UNRELEASED - +* AADRoleSetting + * Export sorted by DisplayName for better comparison + * Enable Filter property to be used on export + FIXES [#3919](https://github.com/microsoft/Microsoft365DSC/issues/3919) * DEPENDENCIES * Updated Microsoft.Graph to version 2.10.0. * Updated MSCloudLoginAssistant to version 1.1.0. diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_AADRoleSetting/MSFT_AADRoleSetting.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_AADRoleSetting/MSFT_AADRoleSetting.psm1 index 4353dd8ce8..117d2e66d8 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_AADRoleSetting/MSFT_AADRoleSetting.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_AADRoleSetting/MSFT_AADRoleSetting.psm1 @@ -1283,6 +1283,7 @@ function Test-TargetResource [Switch] $ManagedIdentity ) + $Script:ExportMode = $false #Ensure the proper dependencies are installed in the current environment. Confirm-M365DSCDependencies @@ -1379,7 +1380,7 @@ function Export-TargetResource try { $Script:ExportMode = $true - [array] $Script:exportedInstances = Get-MgBetaRoleManagementDirectoryRoleDefinition -ErrorAction Stop + [array] $Script:exportedInstances = Get-MgBetaRoleManagementDirectoryRoleDefinition -Filter $Filter -Sort DisplayName -ErrorAction Stop $i = 1 $dscContent = '' Write-Host "`r`n" -NoNewline diff --git a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.AADRoleSetting.Tests.ps1 b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.AADRoleSetting.Tests.ps1 index 31cb22bf3e..5b68626cd5 100644 --- a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.AADRoleSetting.Tests.ps1 +++ b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.AADRoleSetting.Tests.ps1 @@ -660,6 +660,15 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { It 'Should reverse engineer resource from the export method' { $result = Export-TargetResource @testParams + Should -Invoke -Scope It -CommandName 'Get-MgBetaRoleManagementDirectoryRoleDefinition' -ParameterFilter { $Filter -eq '' -and $Sort -eq 'DisplayName' } -Times 1 + $result | Should -Not -BeNullOrEmpty + } + + It 'Should reverse engineer resource from the export method with a filter' { + $testParams.Filter = "displayName eq 'Role1'" + + $result = Export-TargetResource @testParams + Should -Invoke -Scope It -CommandName 'Get-MgBetaRoleManagementDirectoryRoleDefinition' -ParameterFilter { $Filter -eq "displayName eq 'Role1'" -and $Sort -eq 'DisplayName' } -Times 1 $result | Should -Not -BeNullOrEmpty } }