Skip to content

Commit efdcad6

Browse files
authored
Merge pull request #358 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 472cfaa + c3204ee commit efdcad6

7 files changed

+98
-75
lines changed

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardCloudMessageRecall.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function Invoke-CIPPStandardCloudMessageRecall {
3232
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'CloudMessageRecall'
3333

3434
# Get state value using null-coalescing operator
35-
$state = $Settings.state.value ?? $Settings.state
35+
$state = $Settings.state.value
3636

3737
$CurrentState = (New-ExoRequest -tenantid $Tenant -cmdlet 'Get-OrganizationConfig').MessageRecallEnabled
3838
$WantedState = if ($state -eq 'true') { $true } else { $false }
@@ -41,14 +41,14 @@ function Invoke-CIPPStandardCloudMessageRecall {
4141
if ($Settings.report -eq $true) {
4242
# Default is not set, not set means it's enabled
4343
if ($null -eq $CurrentState ) { $CurrentState = $true }
44-
Set-CIPPStandardsCompareField -FieldName 'standards.CloudMessageRecall' -FieldValue $CurrentState -TenantFilter $Tenant
44+
Set-CIPPStandardsCompareField -FieldName 'standards.CloudMessageRecall' -FieldValue $StateIsCorrect -TenantFilter $Tenant
4545
Add-CIPPBPAField -FieldName 'MessageRecall' -FieldValue $CurrentState -StoreAs bool -Tenant $Tenant
4646
}
4747

4848
# Input validation
4949
if (([string]::IsNullOrWhiteSpace($state) -or $state -eq 'Select a value') -and ($Settings.remediate -eq $true -or $Settings.alert -eq $true)) {
5050
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'MessageRecallEnabled: Invalid state parameter set' -sev Error
51-
Return
51+
return
5252
}
5353

5454
if ($Settings.remediate -eq $true) {

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardExternalMFATrusted.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function Invoke-CIPPStandardExternalMFATrusted {
4343
# Input validation
4444
if (([string]::IsNullOrWhiteSpace($state) -or $state -eq 'Select a value') -and ($Settings.remediate -eq $true -or $Settings.alert -eq $true)) {
4545
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'ExternalMFATrusted: Invalid state parameter set' -sev Error
46-
Return
46+
return
4747
}
4848

4949
if ($Settings.remediate -eq $true) {
@@ -66,7 +66,8 @@ function Invoke-CIPPStandardExternalMFATrusted {
6666
}
6767
if ($Settings.report -eq $true) {
6868
$state = $ExternalMFATrusted.inboundTrust.isMfaAccepted ? $true : $ExternalMFATrusted.inboundTrust
69-
Set-CIPPStandardsCompareField -FieldName 'standards.ExternalMFATrusted' -FieldValue $ExternalMFATrusted.inboundTrust.isMfaAccepted -TenantFilter $Tenant
69+
$ReportState = $ExternalMFATrusted.inboundTrust.isMfaAccepted -eq $WantedState
70+
Set-CIPPStandardsCompareField -FieldName 'standards.ExternalMFATrusted' -FieldValue $ReportState -TenantFilter $Tenant
7071
Add-CIPPBPAField -FieldName 'ExternalMFATrusted' -FieldValue $ExternalMFATrusted.inboundTrust.isMfaAccepted -StoreAs bool -Tenant $Tenant
7172
}
7273

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardGroupTemplate.ps1

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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.GroupTemplate' -FieldValue $fieldValue -Tenant $Tenant
134+
}
117135
}

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardMailboxRecipientLimits.ps1

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ function Invoke-CIPPStandardMailboxRecipientLimits {
6969
if ($null -ne $Mailboxes -and @($Mailboxes).Count -gt 0) {
7070
# Process mailboxes and categorize them based on their plan limits
7171
$MailboxResults = @($Mailboxes) | ForEach-Object {
72-
$Mailbox = $_
7372

73+
$Mailbox = $_
74+
if ($Mailbox.UserPrincipalName -like 'DiscoverySearchMailbox*' -or $Mailbox.UserPrincipalName -like 'SystemMailbox*') {
75+
return
76+
}
7477
# Safe hashtable lookup - check if MailboxPlanId exists and is not null
7578
$Plan = $null
7679
if ($Mailbox.MailboxPlanId -and $MailboxPlanLookup.ContainsKey($Mailbox.MailboxPlanId)) {
@@ -83,8 +86,7 @@ function Invoke-CIPPStandardMailboxRecipientLimits {
8386
# If mailbox has "Unlimited" set but has a plan, use the plan's limit as the current limit
8487
$CurrentLimit = if ($Mailbox.RecipientLimits -eq 'Unlimited') {
8588
$PlanMaxRecipients
86-
}
87-
else {
89+
} else {
8890
$Mailbox.RecipientLimits
8991
}
9092

@@ -96,15 +98,13 @@ function Invoke-CIPPStandardMailboxRecipientLimits {
9698
PlanLimit = $PlanMaxRecipients
9799
PlanName = $Plan.DisplayName
98100
}
99-
}
100-
elseif ($CurrentLimit -ne $Settings.RecipientLimit) {
101+
} elseif ($CurrentLimit -ne $Settings.RecipientLimit) {
101102
[PSCustomObject]@{
102103
Type = 'ToUpdate'
103104
Mailbox = $Mailbox
104105
}
105106
}
106-
}
107-
elseif ($Mailbox.RecipientLimits -ne $Settings.RecipientLimit) {
107+
} elseif ($Mailbox.RecipientLimits -ne $Settings.RecipientLimit) {
108108
[PSCustomObject]@{
109109
Type = 'ToUpdate'
110110
Mailbox = $Mailbox
@@ -139,11 +139,11 @@ function Invoke-CIPPStandardMailboxRecipientLimits {
139139
$MailboxChanges = $MailboxesToUpdate | ForEach-Object {
140140
$CurrentLimit = if ($_.RecipientLimits -eq 'Unlimited') { 'Unlimited' } else { $_.RecipientLimits }
141141
@{
142-
Identity = $_.Identity
143-
DisplayName = $_.DisplayName
142+
Identity = $_.Identity
143+
DisplayName = $_.DisplayName
144144
PrimarySmtpAddress = $_.PrimarySmtpAddress
145-
CurrentLimit = $CurrentLimit
146-
NewLimit = $Settings.RecipientLimit
145+
CurrentLimit = $CurrentLimit
146+
NewLimit = $Settings.RecipientLimit
147147
}
148148
}
149149

@@ -165,13 +165,11 @@ function Invoke-CIPPStandardMailboxRecipientLimits {
165165
# Execute batch update
166166
$null = New-ExoBulkRequest -tenantid $Tenant -cmdletArray $UpdateRequests
167167
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Successfully applied recipient limits to $($MailboxesToUpdate.Count) mailboxes" -sev Info
168-
}
169-
catch {
168+
} catch {
170169
$ErrorMessage = Get-CippException -Exception $_
171170
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Could not set recipient limits. $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
172171
}
173-
}
174-
else {
172+
} else {
175173
Write-LogMessage -API 'Standards' -tenant $Tenant -message "All mailboxes already have the correct recipient limit of $($Settings.RecipientLimit)" -sev Info
176174
}
177175
}
@@ -180,12 +178,11 @@ function Invoke-CIPPStandardMailboxRecipientLimits {
180178
if ($Settings.alert -eq $true) {
181179
if ($MailboxesToUpdate.Count -eq 0 -and $MailboxesWithPlanIssues.Count -eq 0) {
182180
Write-LogMessage -API 'Standards' -tenant $Tenant -message "All mailboxes have the correct recipient limit of $($Settings.RecipientLimit)" -sev Info
183-
}
184-
else {
181+
} else {
185182
# Create structured alert data
186183
$AlertData = @{
187-
RequestedLimit = $Settings.RecipientLimit
188-
MailboxesToUpdate = @()
184+
RequestedLimit = $Settings.RecipientLimit
185+
MailboxesToUpdate = @()
189186
MailboxesWithPlanIssues = @()
190187
}
191188

@@ -197,11 +194,11 @@ function Invoke-CIPPStandardMailboxRecipientLimits {
197194
$AlertData.MailboxesToUpdate = $MailboxesToUpdate | ForEach-Object {
198195
$CurrentLimit = if ($_.RecipientLimits -eq 'Unlimited') { 'Unlimited' } else { $_.RecipientLimits }
199196
@{
200-
Identity = $_.Identity
201-
DisplayName = $_.DisplayName
197+
Identity = $_.Identity
198+
DisplayName = $_.DisplayName
202199
PrimarySmtpAddress = $_.PrimarySmtpAddress
203-
CurrentLimit = $CurrentLimit
204-
RequiredLimit = $Settings.RecipientLimit
200+
CurrentLimit = $CurrentLimit
201+
RequiredLimit = $Settings.RecipientLimit
205202
}
206203
}
207204
# Add to alert objects list efficiently
@@ -214,10 +211,10 @@ function Invoke-CIPPStandardMailboxRecipientLimits {
214211
if ($MailboxesWithPlanIssues.Count -gt 0) {
215212
$AlertData.MailboxesWithPlanIssues = $MailboxesWithPlanIssues | ForEach-Object {
216213
@{
217-
Identity = $_.Identity
218-
CurrentLimit = $_.CurrentLimit
219-
PlanLimit = $_.PlanLimit
220-
PlanName = $_.PlanName
214+
Identity = $_.Identity
215+
CurrentLimit = $_.CurrentLimit
216+
PlanLimit = $_.PlanLimit
217+
PlanName = $_.PlanName
221218
RequestedLimit = $Settings.RecipientLimit
222219
}
223220
}
@@ -249,8 +246,7 @@ function Invoke-CIPPStandardMailboxRecipientLimits {
249246

250247
if ($MailboxesToUpdate.Count -eq 0 -and $MailboxesWithPlanIssues.Count -eq 0) {
251248
$FieldValue = $true
252-
}
253-
else {
249+
} else {
254250
$FieldValue = $ReportData
255251
}
256252
Set-CIPPStandardsCompareField -FieldName 'standards.MailboxRecipientLimits' -FieldValue $FieldValue -Tenant $Tenant

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardSafeSendersDisable.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,9 @@ function Invoke-CIPPStandardSafeSendersDisable {
6262
}
6363
}
6464

65+
if ($Settings.report -eq $true) {
66+
#This script always returns true, as it only disables the Safe Senders list
67+
Set-CIPPStandardsCompareField -FieldName 'standards.SafeSendersDisable' -FieldValue $true -Tenant $Tenant
68+
}
69+
6570
}

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardTeamsMeetingRecordingExpiration.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ function Invoke-CIPPStandardTeamsMeetingRecordingExpiration {
7373
if ($Settings.report -eq $true) {
7474
Add-CIPPBPAField -FieldName 'TeamsMeetingRecordingExpiration' -FieldValue $CurrentExpirationDays -StoreAs string -Tenant $Tenant
7575

76-
$CurrentExpirationDays = [PSCustomObject]@{
77-
ExpirationDays = [string]$CurrentExpirationDays
78-
}
76+
$CurrentExpirationDays = if ($StateIsCorrect) { $true } else { $CurrentExpirationDays }
77+
7978
Set-CIPPStandardsCompareField -FieldName 'standards.TeamsMeetingRecordingExpiration' -FieldValue $CurrentExpirationDays -Tenant $Tenant
8079
}
8180
}

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardcalDefault.ps1

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ function Invoke-CIPPStandardcalDefault {
3939
# Input validation
4040
if ([string]::IsNullOrWhiteSpace($permissionLevel) -or $permissionLevel -eq 'Select a value') {
4141
Write-LogMessage -API 'Standards' -tenant $tenant -message 'calDefault: Invalid permissionLevel parameter set' -sev Error
42-
Return
42+
return
4343
}
4444

45-
If ($Settings.remediate -eq $true) {
45+
if ($Settings.remediate -eq $true) {
4646
$Mailboxes = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-Mailbox' | Sort-Object UserPrincipalName
4747
$TotalMailboxes = $Mailboxes.Count
4848
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Started setting default calendar permissions for $($TotalMailboxes) mailboxes." -sev Info
@@ -67,44 +67,48 @@ function Invoke-CIPPStandardcalDefault {
6767
$Mailbox = $_
6868
try {
6969
New-ExoRequest -tenantid $Tenant -cmdlet 'Get-MailboxFolderStatistics' -cmdParams @{identity = $Mailbox.UserPrincipalName; FolderScope = 'Calendar' } -Anchor $Mailbox.UserPrincipalName | Where-Object { $_.FolderType -eq 'Calendar' } |
70-
ForEach-Object {
71-
try {
72-
New-ExoRequest -tenantid $Tenant -cmdlet 'Set-MailboxFolderPermission' -cmdParams @{Identity = "$($Mailbox.UserPrincipalName):$($_.FolderId)"; User = 'Default'; AccessRights = $permissionLevel } -Anchor $Mailbox.UserPrincipalName
73-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Set default folder permission for $($Mailbox.UserPrincipalName):\$($_.Name) to $permissionLevel" -sev Debug
74-
$SuccessCounter++
75-
} catch {
76-
$ErrorMessage = Get-CippException -Exception $_
77-
Write-Host "Setting cal failed: $ErrorMessage"
78-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Could not set default calendar permissions for $($Mailbox.UserPrincipalName). Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
79-
}
70+
ForEach-Object {
71+
try {
72+
New-ExoRequest -tenantid $Tenant -cmdlet 'Set-MailboxFolderPermission' -cmdParams @{Identity = "$($Mailbox.UserPrincipalName):$($_.FolderId)"; User = 'Default'; AccessRights = $permissionLevel } -Anchor $Mailbox.UserPrincipalName
73+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Set default folder permission for $($Mailbox.UserPrincipalName):\$($_.Name) to $permissionLevel" -sev Debug
74+
$SuccessCounter++
75+
} catch {
76+
$ErrorMessage = Get-CippException -Exception $_
77+
Write-Host "Setting cal failed: $ErrorMessage"
78+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Could not set default calendar permissions for $($Mailbox.UserPrincipalName). Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
8079
}
81-
} catch {
82-
$ErrorMessage = Get-CippException -Exception $_
83-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Could not set default calendar permissions for $($Mailbox.UserPrincipalName). Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
84-
}
85-
$processedMailboxes++
86-
if ($processedMailboxes % 25 -eq 0) {
87-
$LastRun = @{
88-
RowKey = 'calDefaults'
89-
PartitionKey = $Tenant
90-
totalMailboxes = $TotalMailboxes
91-
processedMailboxes = $processedMailboxes
92-
currentSuccessCount = $SuccessCounter
93-
}
94-
Add-CIPPAzDataTableEntity @LastRunTable -Entity $LastRun -Force
95-
Write-Host "Processed $processedMailboxes mailboxes"
9680
}
81+
} catch {
82+
$ErrorMessage = Get-CippException -Exception $_
83+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Could not set default calendar permissions for $($Mailbox.UserPrincipalName). Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
9784
}
98-
99-
$LastRun = @{
100-
RowKey = 'calDefaults'
101-
PartitionKey = $Tenant
102-
totalMailboxes = $TotalMailboxes
103-
processedMailboxes = $processedMailboxes
104-
currentSuccessCount = $SuccessCounter
85+
$processedMailboxes++
86+
if ($processedMailboxes % 25 -eq 0) {
87+
$LastRun = @{
88+
RowKey = 'calDefaults'
89+
PartitionKey = $Tenant
90+
totalMailboxes = $TotalMailboxes
91+
processedMailboxes = $processedMailboxes
92+
currentSuccessCount = $SuccessCounter
93+
}
94+
Add-CIPPAzDataTableEntity @LastRunTable -Entity $LastRun -Force
95+
Write-Host "Processed $processedMailboxes mailboxes"
10596
}
106-
Add-CIPPAzDataTableEntity @LastRunTable -Entity $LastRun -Force
97+
}
10798

108-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Successfully set default calendar permissions for $SuccessCounter out of $TotalMailboxes mailboxes." -sev Info
99+
$LastRun = @{
100+
RowKey = 'calDefaults'
101+
PartitionKey = $Tenant
102+
totalMailboxes = $TotalMailboxes
103+
processedMailboxes = $processedMailboxes
104+
currentSuccessCount = $SuccessCounter
109105
}
106+
Add-CIPPAzDataTableEntity @LastRunTable -Entity $LastRun -Force
107+
108+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Successfully set default calendar permissions for $SuccessCounter out of $TotalMailboxes mailboxes." -sev Info
109+
}
110+
if ($Settings.report -eq $true) {
111+
#This script always returns true, as it only disables the Safe Senders list
112+
Set-CIPPStandardsCompareField -FieldName 'standards.SafeSendersDisable' -FieldValue $true -Tenant $Tenant
110113
}
114+
}

0 commit comments

Comments
 (0)