Skip to content

Commit

Permalink
Merge pull request #4305 from ricmestre/fix3959
Browse files Browse the repository at this point in the history
IntuneDeviceAndAppManagementAssignmentFilter: Fix Test-TargetResource to ensure that resource reports its correct state
  • Loading branch information
NikCharlebois authored Feb 14, 2024
2 parents 9d039e4 + e5c1a1b commit 53fc015
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* EXOMobileDeviceMailboxPolicy
* Fixes an issue where an empty MinPasswordLength value was always passed down
to the update logic flow.
* IntuneDeviceAndAppManagementAssignmentFilter
* Fixed Test-TargetResource to ensure that resource reports its correct state
FIXES [#3959](https://github.com/microsoft/Microsoft365DSC/issues/3959)
* IntuneDeviceConfigurationNetworkBoundaryPolicyWindows10
* Fixed Test-TargetResource by removing Id from being tested and also used
correct filter while retrieving the policy otherwise it could not be found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,21 +310,32 @@ function Test-TargetResource
Write-Verbose -Message "Testing configuration of assignment filter {$DisplayName}"

$CurrentValues = Get-TargetResource @PSBoundParameters
$ValuesToCheck = ([Hashtable]$PSBoundParameters).clone()
$ValuesToCheck = Remove-M365DSCAuthenticationParameter -BoundParameters $ValuesToCheck
$ValuesToCheck.Remove('Identity') | Out-Null

Write-Verbose -Message "Current Values: $(Convert-M365DscHashtableToString -Hashtable $CurrentValues)"
Write-Verbose -Message "Target Values: $(Convert-M365DscHashtableToString -Hashtable $PSBoundParameters)"
if ($CurrentValues.Ensure -ne $PSBoundParameters.Ensure)
{
Write-Verbose -Message "Test-TargetResource returned $false"
return $false
}
if ($CurrentValues.Ensure -eq 'Absent' -and $PSBoundParameters.Ensure -eq 'Absent')
{
Write-Verbose -Message "Test-TargetResource returned $true"
return $true
}
$testResult = $true

$ValuesToCheck = $PSBoundParameters
$ValuesToCheck.Remove('Credential') | Out-Null
$ValuesToCheck.Remove('ApplicationId') | Out-Null
$ValuesToCheck.Remove('TenantId') | Out-Null
$ValuesToCheck.Remove('ApplicationSecret') | Out-Null
$ValuesToCheck.Remove('Identity') | Out-Null
Write-Verbose -Message "Current Values: $(Convert-M365DscHashtableToString -Hashtable $CurrentValues)"
Write-Verbose -Message "Target Values: $(Convert-M365DscHashtableToString -Hashtable $ValuesToCheck)"

$TestResult = Test-M365DSCParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck $ValuesToCheck.Keys
if ($TestResult)
{
$TestResult = Test-M365DSCParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck $ValuesToCheck.Keys
}

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

Expand Down

0 comments on commit 53fc015

Please sign in to comment.