# Define the file paths
$downloadsPath = [Environment]::GetFolderPath('MyDocuments') -replace 'Documents$', 'Downloads'
$files = @(
"$downloadsPath\ExchangeDatabaseMailboxListReport.txt",
"$downloadsPath\ExchangeDatabaseMailboxSizeReport.txt",
"$downloadsPath\InactiveMailboxesReport30Days.txt",
"$downloadsPath\SharedMailboxesReport.txt",
"$downloadsPath\EmailForwardingReport.txt",
"$downloadsPath\SharedMailboxMessageCopySettingsReport.txt",
"$downloadsPath\UserMailboxMessageCopySettingsReport.txt"
)
# Loop through each file and generate individual HTML reports
foreach ($file in $files) {
if (Test-Path $file) {
# Generate the HTML file path
$reportName = [System.IO.Path]::GetFileNameWithoutExtension($file)
$htmlFilePath = "$downloadsPath\$reportName.html"
if ($file -like "*ExchangeDatabaseMailboxListReport.txt" -or $file -like "*ExchangeDatabaseMailboxSizeReport.txt") {
# Process Exchange Database Mailbox List/Size Reports
$content = Get-Content -Path $file
$htmlContent = @"
$reportName
$reportName
Database Details
"@
# Parse database and size details
foreach ($line in $content) {
if ($line -match "^Database:\s*(.+)$") {
$database = $matches[1]
$htmlContent += "Database: $database
"
} elseif ($line -match "^Total Size:\s*(.+)$") {
$totalSize = $matches[1]
$htmlContent += "Total Size: $totalSize
"
}
}
# Process User Mailboxes Section
$htmlContent += @"
User Mailboxes
| Display Name |
Email Address |
"@
# Parse User Mailboxes
$inUserMailboxes = $false
foreach ($line in $content) {
if ($line -match "^User Mailboxes:") {
$inUserMailboxes = $true
continue
}
if ($line -match "^Shared Mailboxes:") {
$inUserMailboxes = $false
}
if ($inUserMailboxes -and $line -match "^\s*([^,]+),\s*(\S+@\S+)$") {
$displayName = $matches[1]
$emailAddress = $matches[2]
$htmlContent += "| $displayName | $emailAddress |
"
}
}
# Process Shared Mailboxes Section
$htmlContent += @"
Shared Mailboxes
| Display Name |
Email Address |
"@
$inSharedMailboxes = $false
foreach ($line in $content) {
if ($line -match "^Shared Mailboxes:") {
$inSharedMailboxes = $true
continue
}
if ($inSharedMailboxes -and $line -match "^\s*([^,]+),\s*(\S+@\S+)$") {
$displayName = $matches[1]
$emailAddress = $matches[2]
$htmlContent += "| $displayName | $emailAddress |
"
}
}
$htmlContent += @"
"@
# Save the HTML report
$htmlContent | Set-Content -Path $htmlFilePath -Encoding UTF8
Write-Host "HTML report generated at $htmlFilePath"
} elseif ($file -like "*SharedMailboxesReport.txt") {
# Process plain text Shared Mailboxes Report
$content = Get-Content -Path $file
$htmlContent = @"
Shared Mailboxes Report
Shared Mailboxes Report
User Mailboxes
| Display Name |
Email Address |
"@
# Parse User Mailboxes section
$userSection = $content | Select-String -Pattern "^User Mailboxes:" -Context 1,20
foreach ($line in $userSection.Context.PostContext) {
if ($line -match "^\s*([^,]+),\s*(\S+@\S+)$") {
$displayName = $matches[1]
$emailAddress = $matches[2]
$htmlContent += "| $displayName | $emailAddress |
"
}
}
# Parse Shared Mailboxes section
$htmlContent += @"
Shared Mailboxes
| Display Name |
Email Address |
"@
$sharedSection = $content | Select-String -Pattern "^Shared Mailboxes:" -Context 1,50
foreach ($line in $sharedSection.Context.PostContext) {
if ($line -match "^\s*([^,]+),\s*(\S+@\S+)$") {
$displayName = $matches[1]
$emailAddress = $matches[2]
$htmlContent += "| $displayName | $emailAddress |
"
}
}
$htmlContent += @"
"@
# Save the HTML report
$htmlContent | Set-Content -Path $htmlFilePath -Encoding UTF8
Write-Host "HTML report generated at $htmlFilePath"
}
} else {
Write-Host "File not found: $file" -ForegroundColor Red
}
}