@@ -29,7 +29,7 @@ function Invoke-CIPPStandardGroupTemplate {
2929 #>
3030 param ($Tenant , $Settings )
3131 # #$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'GroupTemplate'
32-
32+ $existingGroups = New-GraphGETRequest - uri ' https://graph.microsoft.com/beta/groups?$top=999 ' - tenantid $tenant
3333 if ($Settings.remediate -eq $true ) {
3434 # Because the list name changed from TemplateList to groupTemplate by someone :@, we'll need to set it back to TemplateList
3535 $Settings.groupTemplate ? ($Settings | Add-Member - NotePropertyName ' TemplateList' - NotePropertyValue $Settings.groupTemplate ) : $null
@@ -40,7 +40,7 @@ function Invoke-CIPPStandardGroupTemplate {
4040 $Filter = " PartitionKey eq 'GroupTemplate' and RowKey eq '$ ( $Template.value ) '"
4141 $groupobj = (Get-AzDataTableEntity @Table - Filter $Filter ).JSON | ConvertFrom-Json
4242 $email = if ($groupobj.domain ) { " $ ( $groupobj.username ) @$ ( $groupobj.domain ) " } else { " $ ( $groupobj.username ) @$ ( $Tenant ) " }
43- $CheckExististing = New-GraphGETRequest - uri ' https://graph.microsoft.com/beta/groups?$top=999 ' - tenantid $tenant | Where-Object - Property displayName -EQ $groupobj.displayname
43+ $CheckExististing = $existingGroups | Where-Object - Property displayName -EQ $groupobj.displayname
4444 $BodyToship = [pscustomobject ] @ {
4545 ' displayName' = $groupobj.Displayname
4646 ' description' = $groupobj.Description
@@ -114,4 +114,22 @@ function Invoke-CIPPStandardGroupTemplate {
114114 }
115115 }
116116 }
117+ if ($Settings.report -eq $true ) {
118+ $Groups = $Settings.groupTemplate.JSON | ConvertFrom-Json - Depth 10
119+ # check if all groups.displayName are in the existingGroups, if not $fieldvalue should contain all missing groups, else it should be true.
120+ $MissingGroups = foreach ($Group in $Groups ) {
121+ $CheckExististing = $existingGroups | Where-Object - Property displayName -EQ $Group.displayname
122+ if (! $CheckExististing ) {
123+ $Group.displayname
124+ }
125+ }
126+
127+ if ($MissingGroups.Count -eq 0 ) {
128+ $fieldValue = $true
129+ } else {
130+ $fieldValue = $MissingGroups -join ' , '
131+ }
132+
133+ Set-CIPPStandardsCompareField - FieldName ' standards.SafeSendersDisable' - FieldValue $fieldValue - Tenant $Tenant
134+ }
117135}
0 commit comments