Skip to content

Commit

Permalink
Merge pull request #4370 from ykuijs/Dev
Browse files Browse the repository at this point in the history
[AADGroup] Fixing issue 4358, using single quotes in DisplayName
  • Loading branch information
ykuijs authored Feb 26, 2024
2 parents 92f2907 + a893dd8 commit 93937c7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

* AADConditionalAccessPolicy
* Improved verbose logging to show that items are being skipped.
* AADGroup
* Fixed issue with single quotes in the display name.
FIXES [#4358](https://github.com/microsoft/Microsoft365DSC/issues/4358)
* EXOActiveSyncDeviceAccessRule
* Remove extra property GUID that is stopping EXO integration tests from
running
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ function Get-TargetResource
Write-Verbose -Message 'GroupID was specified'
try
{
if ($null -ne $Script:exportedGroups-and $Script:ExportMode)
if ($null -ne $Script:exportedGroups -and $Script:ExportMode)
{
$Group = $Script:exportedGroups | Where-Object -FilterScript {$_.Id -eq $Id}
$Group = $Script:exportedGroups | Where-Object -FilterScript { $_.Id -eq $Id }
}
else
{
Expand All @@ -141,13 +141,14 @@ function Get-TargetResource
catch
{
Write-Verbose -Message "Couldn't get group by ID, trying by name"
if ($null -ne $Script:exportedGroups-and $Script:ExportMode)
if ($null -ne $Script:exportedGroups -and $Script:ExportMode)
{
$Group = $Script:exportedGroups | Where-Object -FilterScript {$_.DisplayName -eq $DisplayName}
$Group = $Script:exportedGroups | Where-Object -FilterScript { $_.DisplayName -eq $DisplayName }
}
else
{
$Group = Get-MgGroup -Filter "DisplayName eq '$DisplayName'" -ErrorAction Stop
$filter = "DisplayName eq '$DisplayName'" -replace "'", "''"
$Group = Get-MgGroup -Filter $filter -ErrorAction Stop
}
if ($Group.Length -gt 1)
{
Expand All @@ -159,13 +160,14 @@ function Get-TargetResource
{
Write-Verbose -Message 'Id was NOT specified'
## Can retreive multiple AAD Groups since displayname is not unique
if ($null -ne $Script:exportedGroups-and $Script:ExportMode)
if ($null -ne $Script:exportedGroups -and $Script:ExportMode)
{
$Group = $Script:exportedGroups | Where-Object -FilterScript {$_.DisplayName -eq $DisplayName}
$Group = $Script:exportedGroups | Where-Object -FilterScript { $_.DisplayName -eq $DisplayName }
}
else
{
$Group = Get-MgGroup -Filter "DisplayName eq '$DisplayName'" -ErrorAction Stop
$filter = "DisplayName eq '$DisplayName'" -replace "'", "''"
$Group = Get-MgGroup -Filter $filter -ErrorAction Stop
}
if ($Group.Length -gt 1)
{
Expand Down Expand Up @@ -643,11 +645,11 @@ function Set-TargetResource
}
try
{
New-MgGroupOwnerByRef -GroupId ($currentGroup.Id) -BodyParameter $ownerObject -ErrorAction Stop| Out-Null
New-MgGroupOwnerByRef -GroupId ($currentGroup.Id) -BodyParameter $ownerObject -ErrorAction Stop | Out-Null
}
catch
{
if ($_.Exception.Message -notlike "*One or more added object references already exist for the following modified properties*")
if ($_.Exception.Message -notlike '*One or more added object references already exist for the following modified properties*')
{
throw $_
}
Expand Down Expand Up @@ -1078,29 +1080,32 @@ function Export-TargetResource

# Define the list of attributes
$attributesToCheck = @(
"description",
"displayName",
"hasMembersWithLicenseErrors",
"mail",
"mailNickname",
"onPremisesSecurityIdentifier",
"onPremisesSyncEnabled",
"preferredLanguage"
'description',
'displayName',
'hasMembersWithLicenseErrors',
'mail',
'mailNickname',
'onPremisesSecurityIdentifier',
'onPremisesSyncEnabled',
'preferredLanguage'
)

# Initialize a flag to indicate whether any attribute matches the condition
$matchConditionFound = $false

# Check each attribute in the list
foreach ($attribute in $attributesToCheck) {
if ($Filter -like "*$attribute eq null*") {
foreach ($attribute in $attributesToCheck)
{
if ($Filter -like "*$attribute eq null*")
{
$matchConditionFound = $true
break
}
}

# If any attribute matches, add parameters to $ExportParameters
if ($matchConditionFound -or $Filter -like "*endsWith*") {
if ($matchConditionFound -or $Filter -like '*endsWith*')
{
$ExportParameters.Add('CountVariable', 'count')
$ExportParameters.Add('ConsistencyLevel', 'eventual')
}
Expand Down

0 comments on commit 93937c7

Please sign in to comment.