# Define path for HTML report $outputFile = "$env:USERPROFILE\Downloads\UserMailboxMessageCopySettingsReport(Navitas).html" # Changed filename # Define path for server address and credentials $serverAddressFile = ".\DefaultServer.txt" $credentialFile = ".\AdminCredential.xml" # --- HTML Styling (CSS) --- # (CSS Style remains the same as before) $cssStyle = @" "@ # --- Script Logic --- $session = $null # Initialize session variable # --- Initialize Report Body with Title and Descriptions --- # Start with the main H1 title for User Mailboxes $reportBody = "
Understanding Message Copy Settings for User Mailboxes:
These settings apply when delegation permissions ('Send As' or 'Send on Behalf') are granted to allow one user to send email from another user's mailbox.
MessageCopyForSendOnBehalfEnabled): When True, a copy of emails sent 'on behalf of' this user mailbox is saved to the user mailbox's Sent Items folder. When False, the copy is saved only to the sender's Sent Items folder.MessageCopyForSentAsEnabled): When True, a copy of emails sent 'as' this user mailbox is saved to the user mailbox's Sent Items folder. When False, the copy is saved only to the sender's Sent Items folder.Note: This script is for reporting purposes only and does not modify any settings.
No user mailboxes found.
" # Updated message } # --- Update Logic and Sections REMOVED --- # No filtering, prompting, Set-Mailbox, or "AFTER" report needed. $reportBody += "Report generation complete.
" # Simple completion message } catch { Write-Host "An error occurred: $($_.Exception.Message)" -ForegroundColor Red # Append error details to the report body (which already has title/description) $reportBody += "An error occurred while retrieving user mailbox settings.
" # Updated error context $reportBody += "Error Details:
$([System.Net.WebUtility]::HtmlEncode($_.Exception.Message))
Stack Trace:
$([System.Net.WebUtility]::HtmlEncode($_.Exception.StackTrace) -replace "`n", "
")
Script Line: $($_.InvocationInfo.ScriptLineNumber)
" } } finally { # --- Generate Final HTML Report --- $reportFooter = "" # Assemble the full HTML page # *** Updated Title parameter *** ConvertTo-Html -Head $cssStyle ` -Title "User Mailbox Message Copy Settings Report" ` -Body $reportBody ` -PostContent $reportFooter | Out-File $outputFile -Encoding UTF8 -ErrorAction SilentlyContinue # Check if the file was actually created before trying to open it if (Test-Path $outputFile) { Write-Host "HTML Report saved to: $outputFile" Invoke-Item -Path $outputFile } else { Write-Host "Failed to create the report file at: $outputFile" -ForegroundColor Red } # Clean up Exchange session if ($session -ne $null) { Write-Host "Removing Exchange PSSession..." Remove-PSSession $session Write-Host "Session removed." } }