Skip to content

Commit

Permalink
Merge pull request microsoft#4420 from ricmestre/fix4407
Browse files Browse the repository at this point in the history
TeamsGroupPolicyAssignment: Skip assignments that have orphaned/deleted groups or without display name
  • Loading branch information
NikCharlebois authored Mar 18, 2024
2 parents 592c151 + cd76a8e commit d4fb236
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* IntuneAppConfigurationPolicy
* Fix comparison in Test-TargetResource
FIXES [#4451](https://github.com/microsoft/Microsoft365DSC/issues/4451)
* TeamsGroupPolicyAssignment
* Skip assignments that have orphaned/deleted groups or without display name
instead of throwing an error
FIXES [#4407](https://github.com/microsoft/Microsoft365DSC/issues/4407)
* TeamsTenantDialPlan
* Fix output of property NormalizationRules as a string to the blueprint
FIXES [#4428](https://github.com/microsoft/Microsoft365DSC/issues/4428)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,27 +384,24 @@ function Export-TargetResource
}
$dscContent = [System.Text.StringBuilder]::new()
$j = 1
$totalCount = $instances.Length
foreach ($item in $instances)
{
[array]$Group = Find-CsGroup -SearchQuery $item.GroupId -ExactMatchOnly $true
if ($null -eq $totalCount)
if ($null -eq $Group -or $null -eq $Group.DisplayName)
{
$totalCount = 1
$Message = "Group with Id {$($item.GroupId)} could not be found, skipping assignment"
Write-Host $Message
New-M365DSCLogEntry -Message "Error during Export: $Message" `
-Source $($MyInvocation.MyCommand.Source) `
-TenantId $TenantId `
-Credential $Credential

continue
}
if ($totalCount -Eq 0)
{
$Message = "GPA The CSsGroup with ID {$($item.GroupId)} could not be found"
New-M365DSCLogEntry -Message $Message `
-Source $MyInvocation.MyCommand.ModuleName
Write-Error $Message
$groupDisplayName = ""
} else {
$groupDisplayName = $Group[0].DisplayName
}
Write-Host " |---[$j/$totalCount] GroupPolicyAssignment {$($Group[0].DisplayName)}" -NoNewline

Write-Host " |---[$j/$($instances.Length)] GroupPolicyAssignment {$($Group.DisplayName)-$($item.PolicyType)}" -NoNewline
$results = @{
GroupDisplayName = $groupDisplayName
GroupDisplayName = $Group.DisplayName
GroupId = $item.GroupId
PolicyType = $item.PolicyType
PolicyName = $item.PolicyName
Expand Down

0 comments on commit d4fb236

Please sign in to comment.