Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntuneDeviceConfigurationPolicyWindows10: Support setting assignment groups by display name #3763

Merged
merged 19 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4f0fb5e
Support setting assignment groups by display name
ricmestre Oct 6, 2023
5142a3e
No intention to change this to lowercase
ricmestre Oct 6, 2023
efe6f69
Fix example file
ricmestre Oct 9, 2023
6b43ef3
Change property to odataType and remove groupId if unique
ricmestre Oct 9, 2023
6e1de6c
Missed in previous
ricmestre Oct 9, 2023
0d3028a
Merge branch 'Dev' of https://github.com/microsoft/Microsoft365DSC in…
ricmestre Oct 11, 2023
844ea40
Change property name back to dataType
ricmestre Oct 11, 2023
55dd571
Merge branch 'Dev' of https://github.com/microsoft/Microsoft365DSC in…
ricmestre Oct 11, 2023
4291932
Merge branch 'Dev' into Dev
NikCharlebois Oct 11, 2023
24fe7db
Merge branch 'Dev' of https://github.com/microsoft/Microsoft365DSC in…
ricmestre Oct 11, 2023
b8b267e
Merge branch 'Dev' of github.com:ricmestre/Microsoft365DSC into Dev
ricmestre Oct 11, 2023
67b6fcb
Add groupDisplayName to all MSFT_DeviceManagementConfigurationPolicyA…
ricmestre Oct 11, 2023
59c5d64
Missed in previous
ricmestre Oct 11, 2023
fa16720
Change CIMInstance name back to MSFT_DeviceManagementConfigurationPol…
ricmestre Oct 11, 2023
c6b7091
Remove duplicated property
ricmestre Oct 11, 2023
3c3d24a
Merge branch 'Dev' of https://github.com/microsoft/Microsoft365DSC in…
ricmestre Oct 11, 2023
89a4474
Missed to change CIMInstance name in schema
ricmestre Oct 12, 2023
51453f3
Merge branch 'Dev' of https://github.com/microsoft/Microsoft365DSC in…
ricmestre Oct 16, 2023
bfd2ae2
Fix CIM instance type
ricmestre Oct 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* Added support for retrieved groups as calendar delegates.
* EXODistributionGroup
* Fixes the export of group membership to use Identity.
* IntuneDeviceConfigurationPolicyWindows10
* Support setting assignment groups by display name
* TeamsUpdateManagementPolicy
* Add support for the new acceptable value for UseNewTeamsClient (NewTeamsAsDefault).
* MISC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1980,14 +1980,29 @@ function Get-TargetResource
$assignmentResult = @()
foreach ($assignmentEntry in $AssignmentsValues)
{
$DataType = $assignmentEntry.Target.AdditionalProperties.'@odata.type'
$GroupId = $assignmentEntry.Target.AdditionalProperties.groupId
$GroupDisplayName = $null

if ($DataType -eq "#microsoft.graph.groupAssignmentTarget" -or `
$DataType -eq "#microsoft.graph.exclusionGroupAssignmentTarget") {
$Group = Get-MgGroup -GroupId $GroupId -ErrorAction SilentlyContinue
if ($Group.Count -eq 1)
{
$GroupDisplayName = $Group.DisplayName
$GroupId = $null
}
}

$assignmentValue = @{
dataType = $assignmentEntry.Target.AdditionalProperties.'@odata.type'
dataType = $DataType
deviceAndAppManagementAssignmentFilterType = $(if ($null -ne $assignmentEntry.Target.DeviceAndAppManagementAssignmentFilterType)
{
$assignmentEntry.Target.DeviceAndAppManagementAssignmentFilterType.ToString()
})
deviceAndAppManagementAssignmentFilterId = $assignmentEntry.Target.DeviceAndAppManagementAssignmentFilterId
groupId = $assignmentEntry.Target.AdditionalProperties.groupId
groupId = $GroupId
groupDisplayName = $GroupDisplayName
}
$assignmentResult += $assignmentValue
}
Expand Down Expand Up @@ -3325,7 +3340,66 @@ function Set-TargetResource
$assignmentsHash = @()
foreach ($assignment in $Assignments)
{
$assignmentsHash += Get-M365DSCDRGComplexTypeToHashtable -ComplexObject $Assignment
if ($Assignment.dataType -eq "#microsoft.graph.groupAssignmentTarget" -or `
$Assignment.dataType -eq "#microsoft.graph.exclusionGroupAssignmentTarget")
{
if (![string]::IsNullOrEmpty($Assignment.groupId))
{
$Group = Get-MgGroup -GroupId $Assignment.groupId -ErrorAction SilentlyContinue
$GroupId = $Assignment.groupId
}
else
{
$Group = $null
$GroupId = "null"
}

if ($Group.Count -eq 0)
{
$Message = "Could not find assignment group with id {0}, trying with display name" -f $GroupId
Write-Verbose -Message $Message

if (![string]::IsNullOrEmpty($Assignment.groupDisplayName))
{
$Message = "Checking for the assignment group '{0}'" -f $Assignment.groupDisplayName
Write-Verbose -Message $Message

$Filter = "displayName eq '{0}'" -f $Assignment.groupDisplayName
$Group = Get-MgGroup -Filter $Filter -ErrorAction SilentlyContinue
if ($Group.Count -eq 1)
{
$Message = "Found assignment group '{0}' with id '{1}'" -f $Group.DisplayName, $Group.Id
Write-Verbose -Message $Message

$Assignment.groupId = $Group.Id
}
else
{
if ([string]::IsNullOrEmpty($Assignment.groupId))
{
$Message = "Could not find assignment group, skipping"
continue
}

$Message = "Could not find assignment group '{0}', instead use group with id '{1}'" -f $Assignment.groupDisplayName, $Assignment.groupId
Write-Verbose -Message $Message
}
}
else
{
$Message = "Could not find assignment group, skipping"
Write-Verbose -Message $Message
continue
}
}
}

$assignmentHash = Get-M365DSCDRGComplexTypeToHashtable -ComplexObject $Assignment
if (![string]::IsNullOrEmpty($Assignment.groupDisplayName))
{
$assignmentHash.Remove("groupDisplayName") | Out-Null
}
$assignmentsHash += $assignmentHash
}
Update-DeviceConfigurationPolicyAssignment `
-DeviceConfigurationPolicyId $currentInstance.id `
Expand Down Expand Up @@ -4810,7 +4884,7 @@ function Export-TargetResource
}
if ($Results.Assignments)
{
$complexTypeStringResult = Get-M365DSCDRGComplexTypeToString -ComplexObject $Results.Assignments -CIMInstanceName DeviceManagementConfigurationPolicyAssignments
$complexTypeStringResult = Get-M365DSCDRGComplexTypeToString -ComplexObject $Results.Assignments -CIMInstanceName IntuneDeviceConfigurationPolicyWindows10Assignments
if ($complexTypeStringResult)
{
$Results.Assignments = $complexTypeStringResult
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[ClassVersion("1.0.0.0")]
class MSFT_DeviceManagementConfigurationPolicyAssignments
class MSFT_IntuneDeviceConfigurationPolicyWindows10Assignments
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would result in a breaking change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change really needed? The CIM Instance is embedded into this resource. Are there any other CIM Instances with the previous name somewhere else (and do they have the same properties?

Copy link
Contributor Author

@ricmestre ricmestre Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically almost all Intune resources that support Assignments use exactly the same CIM instance MSFT_DeviceManagementConfigurationPolicyAssignments, which means that in order to support the changes I made in this PR without changing the CIM instance name I would need to change all Intune resources at the same time otherwise it gives error messages when importing the module.

I discussed this privately with Nik several months ago.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do all other resources need the display name parameter? If yes, we should change it globally.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with this PR starting by addressing one resource, and then later submit a larger PR to address them all. However, we need to confirm whether or not we really need to rename the CIMInstance right now for this to work or if this can be done in April. I can hold today's release for a few hours, but if we can't resolve the renaming question soon, this will need to get pushed to next week at a minimum. Thanks

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. What I am suggesting for now is to keep the additional code in, but keep the current CIMInstance name. Then later submit two other PRs. The first one to add the data type to all resources, which could get released anytime when ready, then a second one to rename the CIMInstance which would get release as breaking changes in April. Would that be feasible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

groupDisplayName, not dataType :) But yeah that's what I mentioned keep the code I added, change CIMInstance name back to the original but then I'll need to add groupDisplayName property to all resources in this same PR otherwise it won't work, all resources must be changed at the same time, then the code to make them work could be added later on.

That being said, do you still prefer to have individual CIMInstance names per resource (making those changes in April) or keep the same name for all of them?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming from a standpoint, that we should reuse as much code as possible, and if there is no eminent reason to change the CIM Instance name, I would stick one name across all resources.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I was explaining the current situation to a colleague, I realized that what I am suggesting above doesn't make sense. In doing so, we would end up having two sets of definition for the same CIMInstance namespace. One where datatype is present and one where it isn't. Off course the fix would be to make sure datatype is added to all MSFT_DeviceManagementConfigurationPolicyAssignments schemas. Sorry for not picking up on this earlier. I will go ahead and release 1.23.1011.1 without this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In latest iteration all, well almost all, Intune resources have now an additional property called groupDisplayName inside MSFT_DeviceManagementConfigurationPolicyAssignments.

{
[Write, Description("The type of the target assignment."), ValueMap{"#microsoft.graph.groupAssignmentTarget","#microsoft.graph.allLicensedUsersAssignmentTarget","#microsoft.graph.allDevicesAssignmentTarget","#microsoft.graph.exclusionGroupAssignmentTarget","#microsoft.graph.configurationManagerCollectionAssignmentTarget"}, Values{"#microsoft.graph.groupAssignmentTarget","#microsoft.graph.allLicensedUsersAssignmentTarget","#microsoft.graph.allDevicesAssignmentTarget","#microsoft.graph.exclusionGroupAssignmentTarget","#microsoft.graph.configurationManagerCollectionAssignmentTarget"}] String dataType;
[Write, Description("The type of filter of the target assignment i.e. Exclude or Include. Possible values are:none, include, exclude."), ValueMap{"none","include","exclude"}, Values{"none","include","exclude"}] String deviceAndAppManagementAssignmentFilterType;
[Write, Description("The Id of the filter for the target assignment.")] String deviceAndAppManagementAssignmentFilterId;
[Write, Description("The group Id that is the target of the assignment.")] String groupId;
[Write, Description("The group Display Name that is the target of the assignment.")] String groupDisplayName;
[Write, Description("The collection Id that is the target of the assignment.(ConfigMgr)")] String collectionId;
};
[ClassVersion("1.0.0")]
Expand Down Expand Up @@ -332,7 +333,7 @@ class MSFT_IntuneDeviceConfigurationPolicyWindows10 : OMI_BaseResource
[Key, Description("Admin provided name of the device configuration.")] String DisplayName;
[Write, Description("Indicates whether or not the underlying Device Configuration supports the assignment of scope tags. Assigning to the ScopeTags property is not allowed when this value is false and entities will not be visible to scoped users. This occurs for Legacy policies created in Silverlight and can be resolved by deleting and recreating the policy in the Azure Portal. This property is read-only.")] Boolean SupportsScopeTags;
[Write, Description("The unique identifier for an entity. Read-only.")] String Id;
[Write, Description("Represents the assignment to the Intune policy."), EmbeddedInstance("MSFT_DeviceManagementConfigurationPolicyAssignments")] String Assignments[];
[Write, Description("Represents the assignment to the Intune policy."), EmbeddedInstance("MSFT_IntuneDeviceConfigurationPolicyWindows10Assignments")] String Assignments[];
[Write, Description("Present ensures the policy exists, absent ensures it is removed."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure;
[Write, Description("Credentials of the Admin"), EmbeddedInstance("MSFT_Credential")] string Credential;
[Write, Description("Id of the Azure Active Directory application to authenticate with.")] String ApplicationId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Configuration Example
AppsAllowTrustedAppsSideloading = "notConfigured";
AppsBlockWindowsStoreOriginatedApps = $False;
Assignments = @(
MSFT_DeviceManagementConfigurationPolicyAssignments{
MSFT_IntuneDeviceConfigurationPolicyWindows10Assignments{
deviceAndAppManagementAssignmentFilterType = 'none'
dataType = '#microsoft.graph.allDevicesAssignmentTarget'
}
Expand Down