From 2b39cb45d58cbd9d5362b5e501c17822d34cae6c Mon Sep 17 00:00:00 2001 From: William-francillette Date: Fri, 15 Dec 2023 18:27:18 +0000 Subject: [PATCH 1/3] PR:IntuneDeviceEnrollmentPlatformRestriction - Fixes 3730 --- CHANGELOG.md | 6 ++++++ .../MSFT_IntuneDeviceEnrollmentPlatformRestriction.psm1 | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f48faddcf..1713271049 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change log for Microsoft365DSC +# UNRELEASED + +* IntuneDeviceEnrollmentPlatformRestriction + * Fix Set-TargetResource due to an issue were the bodyparameter not cast correctly + FIXES [#3730](https://github.com/microsoft/Microsoft365DSC/issues/3730) + # 1.23.1213.1 * IntuneEndpointDetectionAndResponsePolicyWindows10 diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_IntuneDeviceEnrollmentPlatformRestriction/MSFT_IntuneDeviceEnrollmentPlatformRestriction.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_IntuneDeviceEnrollmentPlatformRestriction/MSFT_IntuneDeviceEnrollmentPlatformRestriction.psm1 index 40e5fe25fe..3091ac55e8 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_IntuneDeviceEnrollmentPlatformRestriction/MSFT_IntuneDeviceEnrollmentPlatformRestriction.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_IntuneDeviceEnrollmentPlatformRestriction/MSFT_IntuneDeviceEnrollmentPlatformRestriction.psm1 @@ -326,10 +326,10 @@ function Set-TargetResource } $PSBoundParameters.add('@odata.type', $policyType) - Write-Verbose ($PSBoundParameters | ConvertTo-Json -Depth 20) + #Write-Verbose ($PSBoundParameters | ConvertTo-Json -Depth 20) $policy = New-MgBetaDeviceManagementDeviceEnrollmentConfiguration ` - -BodyParameter $PSBoundParameters + -BodyParameter ([hashtable]$PSBoundParameters) #Assignments from DefaultPolicy are not editable and will raise an alert if ($policy.Id -notlike '*_DefaultPlatformRestrictions') @@ -384,9 +384,9 @@ function Set-TargetResource $policyType = '#microsoft.graph.deviceEnrollmentPlatformRestrictionsConfiguration' } $PSBoundParameters.add('@odata.type', $policyType) - Write-Verbose ($PSBoundParameters | ConvertTo-Json -Depth 20) + #Write-Verbose ($PSBoundParameters | ConvertTo-Json -Depth 20) Update-MgBetaDeviceManagementDeviceEnrollmentConfiguration ` - -BodyParameter $PSBoundParameters ` + -BodyParameter ([hashtable]$PSBoundParameters) ` -DeviceEnrollmentConfigurationId $Identity #Assignments from DefaultPolicy are not editable and will raise an alert From a40423304535797593a79f479d79531e659a08c6 Mon Sep 17 00:00:00 2001 From: William-francillette Date: Tue, 19 Dec 2023 09:20:51 +0000 Subject: [PATCH 2/3] fixed Test-TargetResource --- ...ntuneDeviceEnrollmentPlatformRestriction.psm1 | 16 +++------------- ...sAutopilotDeploymentProfileAzureADJoined.psm1 | 6 ------ 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_IntuneDeviceEnrollmentPlatformRestriction/MSFT_IntuneDeviceEnrollmentPlatformRestriction.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_IntuneDeviceEnrollmentPlatformRestriction/MSFT_IntuneDeviceEnrollmentPlatformRestriction.psm1 index 3091ac55e8..646a6fcdc3 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_IntuneDeviceEnrollmentPlatformRestriction/MSFT_IntuneDeviceEnrollmentPlatformRestriction.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_IntuneDeviceEnrollmentPlatformRestriction/MSFT_IntuneDeviceEnrollmentPlatformRestriction.psm1 @@ -274,14 +274,7 @@ function Set-TargetResource #endregion $currentCategory = Get-TargetResource @PSBoundParameters - $PSBoundParameters.Remove('Credential') | Out-Null - $PSBoundParameters.Remove('ApplicationId') | Out-Null - $PSBoundParameters.Remove('TenantId') | Out-Null - $PSBoundParameters.Remove('ApplicationSecret') | Out-Null - $PSBoundParameters.Remove('ManagedIdentity') | Out-Null - $PSBoundParameters.Remove('Ensure') | Out-Null - $PSBoundParameters.Remove('CertificateThumbprint') | Out-Null - $PSBoundParameters.Remove('Verbose') | Out-Null + $PSBoundParameters = Remove-M365DSCAuthenticationParameter -BoundParameters $PSBoundParameters $PSBoundParameters.Remove('Identity') | Out-Null if ($Ensure -eq 'Present' -and $currentCategory.Ensure -eq 'Absent') @@ -547,11 +540,8 @@ function Test-TargetResource } } - $ValuesToCheck.Remove('Credential') | Out-Null - $ValuesToCheck.Remove('ApplicationId') | Out-Null - $ValuesToCheck.Remove('TenantId') | Out-Null - $ValuesToCheck.Remove('ApplicationSecret') | Out-Null - $ValuesToCheck.Remove('Id') | Out-Null + $ValuesToCheck = Remove-M365DSCAuthenticationParameter -BoundParameters $ValuesToCheck + $ValuesToCheck.Remove('Identity') | Out-Null $ValuesToCheck.Remove('WindowsMobileRestriction') | Out-Null #Convert any DateTime to String diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_IntuneWindowsAutopilotDeploymentProfileAzureADJoined/MSFT_IntuneWindowsAutopilotDeploymentProfileAzureADJoined.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_IntuneWindowsAutopilotDeploymentProfileAzureADJoined/MSFT_IntuneWindowsAutopilotDeploymentProfileAzureADJoined.psm1 index ff01ef6f85..605ad7f2fd 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_IntuneWindowsAutopilotDeploymentProfileAzureADJoined/MSFT_IntuneWindowsAutopilotDeploymentProfileAzureADJoined.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_IntuneWindowsAutopilotDeploymentProfileAzureADJoined/MSFT_IntuneWindowsAutopilotDeploymentProfileAzureADJoined.psm1 @@ -591,12 +591,6 @@ function Test-TargetResource } } - $ValuesToCheck.Remove('Id') | Out-Null - $ValuesToCheck.Remove('Credential') | Out-Null - $ValuesToCheck.Remove('ApplicationId') | Out-Null - $ValuesToCheck.Remove('TenantId') | Out-Null - $ValuesToCheck.Remove('ApplicationSecret') | Out-Null - Write-Verbose -Message "Current Values: $(Convert-M365DscHashtableToString -Hashtable $CurrentValues)" Write-Verbose -Message "Target Values: $(Convert-M365DscHashtableToString -Hashtable $ValuesToCheck)" From 4662fbec042d44514425c4cc5fdc872e74f4a431 Mon Sep 17 00:00:00 2001 From: William-francillette Date: Tue, 19 Dec 2023 14:52:27 +0000 Subject: [PATCH 3/3] fixed Test-TargetResource --- .../MSFT_IntuneDeviceEnrollmentPlatformRestriction.psm1 | 2 +- ...ft365DSC.IntuneDeviceEnrollmentPlatformRestriction.Tests.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_IntuneDeviceEnrollmentPlatformRestriction/MSFT_IntuneDeviceEnrollmentPlatformRestriction.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_IntuneDeviceEnrollmentPlatformRestriction/MSFT_IntuneDeviceEnrollmentPlatformRestriction.psm1 index 646a6fcdc3..99eb5b034f 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_IntuneDeviceEnrollmentPlatformRestriction/MSFT_IntuneDeviceEnrollmentPlatformRestriction.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_IntuneDeviceEnrollmentPlatformRestriction/MSFT_IntuneDeviceEnrollmentPlatformRestriction.psm1 @@ -510,7 +510,7 @@ function Test-TargetResource $CurrentValues = Get-TargetResource @PSBoundParameters $ValuesToCheck = ([Hashtable]$PSBoundParameters).clone() - if ($CurrentValues.Ensure -eq 'Absent') + if ($CurrentValues.Ensure -ne $Ensure) { Write-Verbose -Message "Test-TargetResource returned $false" return $false diff --git a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.IntuneDeviceEnrollmentPlatformRestriction.Tests.ps1 b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.IntuneDeviceEnrollmentPlatformRestriction.Tests.ps1 index ca9bef9034..7859f4063d 100644 --- a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.IntuneDeviceEnrollmentPlatformRestriction.Tests.ps1 +++ b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.IntuneDeviceEnrollmentPlatformRestriction.Tests.ps1 @@ -207,7 +207,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } It 'Should return true from the Test method' { - Test-TargetResource @testParams | Should -Be $false + Test-TargetResource @testParams| Should -Be $false } It 'Should remove the restriction from the Set method' {