Skip to content

Commit

Permalink
Merge pull request #1242 from kris6673/calDefaults-logging
Browse files Browse the repository at this point in the history
Improve logging for calDefaults
  • Loading branch information
KelvinTegelaar authored Jan 19, 2025
2 parents b9cfa1e + 39cabcd commit 9ee4bd7
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardcalDefault.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,44 +64,44 @@ function Invoke-CIPPStandardcalDefault {
$Mailbox = $_
try {
New-ExoRequest -tenantid $Tenant -cmdlet 'Get-MailboxFolderStatistics' -cmdParams @{identity = $Mailbox.UserPrincipalName; FolderScope = 'Calendar' } -Anchor $Mailbox.UserPrincipalName | Where-Object { $_.FolderType -eq 'Calendar' } |
ForEach-Object {
try {
New-ExoRequest -tenantid $Tenant -cmdlet 'Set-MailboxFolderPermission' -cmdparams @{Identity = "$($Mailbox.UserPrincipalName):$($_.FolderId)"; User = 'Default'; AccessRights = $Settings.permissionlevel } -Anchor $Mailbox.UserPrincipalName
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Set default folder permission for $($Mailbox.UserPrincipalName):\$($_.Name) to $($Settings.permissionlevel)" -sev Debug
$SuccessCounter++
} catch {
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
Write-Host "Setting cal failed: $ErrorMessage"
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Could not set default calendar permissions for $($Mailbox.UserPrincipalName). Error: $ErrorMessage" -sev Error
ForEach-Object {
try {
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Set-MailboxFolderPermission' -cmdParams @{Identity = "$($Mailbox.UserPrincipalName):$($_.FolderId)"; User = 'Default'; AccessRights = $Settings.permissionlevel } -Anchor $Mailbox.UserPrincipalName
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Set default folder permission for $($Mailbox.UserPrincipalName):\$($_.Name) to $($Settings.permissionlevel)" -sev Debug
$SuccessCounter++
} catch {
$ErrorMessage = Get-CippException -Exception $_
Write-Host "Setting cal failed: $ErrorMessage"
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Could not set default calendar permissions for $($Mailbox.UserPrincipalName). Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
}
}
} catch {
$ErrorMessage = Get-CippException -Exception $_
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Could not set default calendar permissions for $($Mailbox.UserPrincipalName). Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
}
} catch {
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Could not set default calendar permissions for $($Mailbox.UserPrincipalName). Error: $ErrorMessage" -sev Error
}
$processedMailboxes++
if ($processedMailboxes % 25 -eq 0) {
$LastRun = @{
RowKey = 'calDefaults'
PartitionKey = $Tenant
totalMailboxes = $TotalMailboxes
processedMailboxes = $processedMailboxes
currentSuccessCount = $SuccessCounter
$processedMailboxes++
if ($processedMailboxes % 25 -eq 0) {
$LastRun = @{
RowKey = 'calDefaults'
PartitionKey = $Tenant
totalMailboxes = $TotalMailboxes
processedMailboxes = $processedMailboxes
currentSuccessCount = $SuccessCounter
}
Add-CIPPAzDataTableEntity @LastRunTable -Entity $LastRun -Force
Write-Host "Processed $processedMailboxes mailboxes"
}
Add-CIPPAzDataTableEntity @LastRunTable -Entity $LastRun -Force
Write-Host "Processed $processedMailboxes mailboxes"
}
}

$LastRun = @{
RowKey = 'calDefaults'
PartitionKey = $Tenant
totalMailboxes = $TotalMailboxes
processedMailboxes = $processedMailboxes
currentSuccessCount = $SuccessCounter
}
Add-CIPPAzDataTableEntity @LastRunTable -Entity $LastRun -Force
$LastRun = @{
RowKey = 'calDefaults'
PartitionKey = $Tenant
totalMailboxes = $TotalMailboxes
processedMailboxes = $processedMailboxes
currentSuccessCount = $SuccessCounter
}
Add-CIPPAzDataTableEntity @LastRunTable -Entity $LastRun -Force

Write-LogMessage -API 'Standards' -tenant $Tenant -message "Successfully set default calendar permissions for $SuccessCounter out of $TotalMailboxes mailboxes." -sev Info
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Successfully set default calendar permissions for $SuccessCounter out of $TotalMailboxes mailboxes." -sev Info
}
}
}

0 comments on commit 9ee4bd7

Please sign in to comment.