Skip to content

Commit

Permalink
Merge pull request #5627 from AlfredSchreuder/Dev
Browse files Browse the repository at this point in the history
Fix duplicate policy creation bug & dynamic group compliance
  • Loading branch information
NikCharlebois authored Jan 15, 2025
2 parents 597160f + a9ee734 commit 69f160d
Show file tree
Hide file tree
Showing 16 changed files with 279 additions and 37 deletions.
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,38 @@
* AADAuthenticationRequirement
* Filtered guests from the export, to prevent errors during export
FIXES [#5625](https://github.com/microsoft/Microsoft365DSC/issues/5625)
* AADGroup
* Only get Members & GroupAsMembers when a static group is defined.
* AADGroupEligibilitySchedule
* New resource for Privileged Identity Management (PIM) for Groups
* IntuneAccountProtectionLocalAdministratorPasswordSolutionPolicy
* Fixed creation of policy while it was found by name, now it updates existing policies correctly.
* IntuneAccountProtectionPolicyWindows10
* Fixed creation of policy while it was found by name, now it updates existing policies correctly.
* IntuneAntivirusPolicyLinux
* Fixed creation of policy while it was found by name, now it updates existing policies correctly.
* IntuneAntivirusPolicyMacOS
* Fixed creation of policy while it was found by name, now it updates existing policies correctly.
* IntuneAntivirusPolicyWindows10SettingCatalog
* Fixed creation of policy while it was found by name, now it updates existing policies correctly.
* IntuneAppAndBrowserIsolationPolicyWindows10
* Fixed creation of policy while it was found by name, now it updates existing policies correctly.
* IntuneDeviceControlPolicyWindows10
* Fixed creation of policy while it was found by name, now it updates existing policies correctly.
* IntuneDiskEncryptionMacOS
* Fixed creation of policy while it was found by name, now it updates existing policies correctly.
* IntuneDiskEncryptionWindows10
* Fixed creation of policy while it was found by name, now it updates existing policies correctly.
* IntuneEndpointDetectionAndResponsePolicyLinux
* Fixed creation of policy while it was found by name, now it updates existing policies correctly.
* IntuneEndpointDetectionAndResponsePolicyMacOS
* Fixed creation of policy while it was found by name, now it updates existing policies correctly.
* IntuneEndpointDetectionAndResponsePolicyWindows10
* Fixed creation of policy while it was found by name, now it updates existing policies correctly.
* IntuneFirewallPolicyWindows10
* Fixed creation of policy while it was found by name, now it updates existing policies correctly.
* IntuneSettingCatalogASRRulesPolicyWindows10
* Fixed creation of policy while it was found by name, now it updates existing policies correctly.
* AADNamingLocationPolicy
* Improved logging and fixed issue that caused creation of duplicate
locations with same name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ function Get-TargetResource
}

$MembersValues = $null
$result = @{}
if ($Group.MembershipRuleProcessingState -ne 'On')
{
# Members
Expand All @@ -237,6 +238,8 @@ function Get-TargetResource
$GroupAsMembersValues += $member.AdditionalProperties.displayName
}
}
$result.Add('Members', $MembersValues)
$result.Add('GroupAsMembers', $GroupAsMembersValues)
}

# MemberOf
Expand Down Expand Up @@ -276,12 +279,10 @@ function Get-TargetResource

}

$result = @{
$policySettings = @{
DisplayName = $Group.DisplayName
Id = $Group.Id
Owners = $OwnersValues
Members = $MembersValues
GroupAsMembers = $GroupAsMembersValues
MemberOf = $MemberOfValues
Description = $Group.Description
GroupTypes = [System.String[]]$Group.GroupTypes
Expand All @@ -303,6 +304,7 @@ function Get-TargetResource
Managedidentity = $ManagedIdentity.IsPresent
AccessTokens = $AccessTokens
}
$result += $policySettings

return $result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ function Get-TargetResource

# Retrieve policy general settings
$policy = $null
$policy = Get-MgBetaDeviceManagementConfigurationPolicy -DeviceManagementConfigurationPolicyId $Identity -ErrorAction SilentlyContinue
if (-not [System.String]::IsNullOrEmpty($Identity))
{
$policy = Get-MgBetaDeviceManagementConfigurationPolicy -DeviceManagementConfigurationPolicyId $Identity -ErrorAction SilentlyContinue
}

if ($null -eq $policy)
{
Expand All @@ -147,6 +150,11 @@ function Get-TargetResource
$policy = Get-MgBetaDeviceManagementConfigurationPolicy `
-Filter "Name eq '$DisplayName' and templateReference/TemplateId eq '$templateReferenceId'" `
-ErrorAction SilentlyContinue

if ($policy.Length -gt 1)
{
throw "Duplicate Account Protection LAPS Policy named $DisplayName exist in tenant"
}
}
}

Expand Down Expand Up @@ -207,6 +215,12 @@ function Get-TargetResource
-TenantId $TenantId `
-Credential $Credential

# Necessary to rethrow caught exception regarding duplicate policies
if ($_.Exception.Message -like "Duplicate*")
{
throw $_
}

$nullResult = Clear-M365DSCAuthenticationParameter -BoundParameters $nullResult
return $nullResult
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ function Get-TargetResource

$getValue = $null
#region resource generator code
$getValue = Get-MgBetaDeviceManagementConfigurationPolicy -DeviceManagementConfigurationPolicyId $Id -ErrorAction SilentlyContinue
if (-not [System.String]::IsNullOrEmpty($Id))
{
$getValue = Get-MgBetaDeviceManagementConfigurationPolicy -DeviceManagementConfigurationPolicyId $Id -ErrorAction SilentlyContinue
}

if ($null -eq $getValue)
{
Expand All @@ -102,6 +105,11 @@ function Get-TargetResource
-All `
-Filter "Name eq '$DisplayName'" `
-ErrorAction SilentlyContinue

if ($getValue.Length -gt 1)
{
throw "Duplicate Intune Account Protection Policy for Windows10 named $DisplayName exist in tenant"
}
}
}
#endregion
Expand Down Expand Up @@ -268,6 +276,13 @@ function Get-TargetResource
-TenantId $TenantId `
-Credential $Credential

# Necessary to rethrow caught exception regarding duplicate policies
if ($_.Exception.Message -like "Duplicate*")
{
throw $_
}

$nullResult = Clear-M365DSCAuthenticationParameter -BoundParameters $nullResult
return $nullResult
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ function Get-TargetResource

$getValue = $null
#region resource generator code
$getValue = Get-MgBetaDeviceManagementConfigurationPolicy -DeviceManagementConfigurationPolicyId $Id -ErrorAction SilentlyContinue
if (-not [System.String]::IsNullOrEmpty($Id))
{
$getValue = Get-MgBetaDeviceManagementConfigurationPolicy -DeviceManagementConfigurationPolicyId $Id -ErrorAction SilentlyContinue
}

if ($null -eq $getValue)
{
Expand All @@ -209,6 +212,11 @@ function Get-TargetResource
-All `
-Filter "Name eq '$DisplayName'" `
-ErrorAction SilentlyContinue

if ($getValue.Length -gt 1)
{
throw "Duplicate Intune Antivirus Policy for Linux named $DisplayName exist in tenant"
}
}
}
#endregion
Expand Down Expand Up @@ -325,6 +333,13 @@ function Get-TargetResource
-TenantId $TenantId `
-Credential $Credential

# Necessary to rethrow caught exception regarding duplicate policies
if ($_.Exception.Message -like "Duplicate*")
{
throw $_
}

$nullResult = Clear-M365DSCAuthenticationParameter -BoundParameters $nullResult
return $nullResult
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ function Get-TargetResource

$getValue = $null
#region resource generator code
$getValue = Get-MgBetaDeviceManagementConfigurationPolicy -DeviceManagementConfigurationPolicyId $Id -ErrorAction SilentlyContinue
if (-not [System.String]::IsNullOrEmpty($Id))
{
$getValue = Get-MgBetaDeviceManagementConfigurationPolicy -DeviceManagementConfigurationPolicyId $Id -ErrorAction SilentlyContinue
}

if ($null -eq $getValue)
{
Expand All @@ -209,9 +212,14 @@ function Get-TargetResource
if (-not [System.String]::IsNullOrEmpty($DisplayName))
{
$getValue = Get-MgBetaDeviceManagementConfigurationPolicy `
-Filter "Name eq '$DisplayName'" `
-All `
-Filter "Name eq '$DisplayName'" `
-ErrorAction SilentlyContinue

if ($getValue.Length -gt 1)
{
throw "Duplicate Intune Antivirus Policy for macOS named $DisplayName exist in tenant"
}
}
}
#endregion
Expand Down Expand Up @@ -322,6 +330,13 @@ function Get-TargetResource
-TenantId $TenantId `
-Credential $Credential

# Necessary to rethrow caught exception regarding duplicate policies
if ($_.Exception.Message -like "Duplicate*")
{
throw $_
}

$nullResult = Clear-M365DSCAuthenticationParameter -BoundParameters $nullResult
return $nullResult
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,12 @@ function Get-TargetResource

$templateReferences = 'd948ff9b-99cb-4ee0-8012-1fbc09685377_1', 'e3f74c5a-a6de-411d-aef6-eb15628f3a0a_1', '45fea5e9-280d-4da1-9792-fb5736da0ca9_1', '804339ad-1553-4478-a742-138fb5807418_1'

#Retrieve policy general settings
$policy = Get-MgBetaDeviceManagementConfigurationPolicy -DeviceManagementConfigurationPolicyId $Identity -ErrorAction SilentlyContinue
# Retrieve policy general settings
$policy = $null
if (-not [System.String]::IsNullOrEmpty($Identity))
{
$policy = Get-MgBetaDeviceManagementConfigurationPolicy -DeviceManagementConfigurationPolicyId $Identity -ErrorAction SilentlyContinue
}

if ($null -eq $policy)
{
Expand All @@ -459,6 +463,11 @@ function Get-TargetResource
-ErrorAction SilentlyContinue | Where-Object `
-FilterScript {
$_.TemplateReference.TemplateId -in $templateReferences
}

if ($policy.Length -gt 1)
{
throw "Duplicate Intune Antivirus Policy for Windows10 Setting Catalog named $DisplayName exist in tenant"
}
}
}
Expand Down Expand Up @@ -537,6 +546,12 @@ function Get-TargetResource
-TenantId $TenantId `
-Credential $Credential

# Necessary to rethrow caught exception regarding duplicate policies
if ($_.Exception.Message -like "Duplicate*")
{
throw $_
}

$nullResult = Clear-M365DSCAuthenticationParameter -BoundParameters $nullResult
return $nullResult
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ function Get-TargetResource

$getValue = $null
#region resource generator code
$getValue = Get-MgBetaDeviceManagementConfigurationPolicy -DeviceManagementConfigurationPolicyId $Id -ErrorAction SilentlyContinue
if (-not [System.String]::IsNullOrEmpty($Id))
{
$getValue = Get-MgBetaDeviceManagementConfigurationPolicy -DeviceManagementConfigurationPolicyId $Id -ErrorAction SilentlyContinue
}

if ($null -eq $getValue)
{
Expand All @@ -182,6 +185,11 @@ function Get-TargetResource
-All `
-Filter "Name eq '$DisplayName'" `
-ErrorAction SilentlyContinue

if ($getValue.Length -gt 1)
{
throw "Duplicate Intune App And Browser Isolation Policy for Windows10 named $DisplayName exist in tenant"
}
}
}
#endregion
Expand Down Expand Up @@ -237,6 +245,13 @@ function Get-TargetResource
-TenantId $TenantId `
-Credential $Credential

# Necessary to rethrow caught exception regarding duplicate policies
if ($_.Exception.Message -like "Duplicate*")
{
throw $_
}

$nullResult = Clear-M365DSCAuthenticationParameter -BoundParameters $nullResult
return $nullResult
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ function Get-TargetResource

$getValue = $null
#region resource generator code
$getValue = Get-MgBetaDeviceManagementConfigurationPolicy -DeviceManagementConfigurationPolicyId $Id -ErrorAction SilentlyContinue
if (-not [System.String]::IsNullOrEmpty($Id))
{
$getValue = Get-MgBetaDeviceManagementConfigurationPolicy -DeviceManagementConfigurationPolicyId $Id -ErrorAction SilentlyContinue
}

if ($null -eq $getValue)
{
Expand All @@ -268,6 +271,11 @@ function Get-TargetResource
-All `
-Filter "Name eq '$DisplayName'" `
-ErrorAction SilentlyContinue

if ($getValue.Length -gt 1)
{
throw "Duplicate Intune Device Control Policy for Windows10 named $DisplayName exist in tenant"
}
}
}
#endregion
Expand Down Expand Up @@ -349,6 +357,13 @@ function Get-TargetResource
-TenantId $TenantId `
-Credential $Credential

# Necessary to rethrow caught exception regarding duplicate policies
if ($_.Exception.Message -like "Duplicate*")
{
throw $_
}

$nullResult = Clear-M365DSCAuthenticationParameter -BoundParameters $nullResult
return $nullResult
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ function Get-TargetResource

$getValue = $null
#region resource generator code
$getValue = Get-MgBetaDeviceManagementIntent -DeviceManagementIntentId $Id -ErrorAction SilentlyContinue
if (-not [System.String]::IsNullOrEmpty($Id))
{
$getValue = Get-MgBetaDeviceManagementIntent -DeviceManagementIntentId $Id -ErrorAction SilentlyContinue
}

if ($null -eq $getValue)
{
Expand All @@ -132,6 +135,11 @@ function Get-TargetResource
-FilterScript { `
$_.TemplateId -eq 'a239407c-698d-4ef8-b314-e3ae409204b8' `
}

if ($getValue.Length -gt 1)
{
throw "Duplicate Intune Disk Encryption for macOS named $DisplayName exist in tenant"
}
}
}
#endregion
Expand Down Expand Up @@ -192,6 +200,13 @@ function Get-TargetResource
-TenantId $TenantId `
-Credential $Credential

# Necessary to rethrow caught exception regarding duplicate policies
if ($_.Exception.Message -like "Duplicate*")
{
throw $_
}

$nullResult = Clear-M365DSCAuthenticationParameter -BoundParameters $nullResult
return $nullResult
}
}
Expand Down
Loading

0 comments on commit 69f160d

Please sign in to comment.