Skip to content

Commit

Permalink
Merge pull request #4054 from William-Francillette/fix3730
Browse files Browse the repository at this point in the history
PR:IntuneDeviceEnrollmentPlatformRestriction - Fixes 3730
  • Loading branch information
NikCharlebois authored Dec 19, 2023
2 parents 2a3a093 + 5074432 commit 4482460
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 25 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* IntuneDeviceConfigurationCustomPolicyWindows10
* Add support to decrypt encrypted OmaSettings and export them in plaintext
FIXES [#3655](https://github.com/microsoft/Microsoft365DSC/issues/3655)
* IntuneDeviceEnrollmentPlatformRestriction
* Fix Set-TargetResource due to an issue were the bodyparameter not cast correctly
FIXES [#3730](https://github.com/microsoft/Microsoft365DSC/issues/3730)
* IntuneEndpointDetectionAndResponsePolicyWindows10
* Fix issue when trying to remove policy and Identity is set to a random GUID
or from another tenant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -326,10 +319,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')
Expand Down Expand Up @@ -384,9 +377,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
Expand Down Expand Up @@ -517,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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' {
Expand Down

0 comments on commit 4482460

Please sign in to comment.