# Check Lesley's email activity since disable
$ErrorActionPreference = "Stop"
$lesleyUPN = "lesley@bgbuildersllc.com"

Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -UserPrincipalName "sysadmin@bgbuildersllc.com" -ShowBanner:$false

$startDate = (Get-Date).AddDays(-3)
$endDate = Get-Date

Write-Output "=== MAILBOX STATUS ==="
$mbx = Get-Mailbox -Identity $lesleyUPN
$stats = Get-MailboxStatistics -Identity $lesleyUPN
Write-Output "Type: $($mbx.RecipientTypeDetails)"
Write-Output "LitigationHold: $($mbx.LitigationHoldEnabled)"
Write-Output "ItemCount: $($stats.ItemCount)"
Write-Output "TotalSize: $($stats.TotalItemSize)"

Write-Output "`n=== SENT MESSAGES (last 3 days) ==="
$sent = Get-MessageTraceV2 -SenderAddress $lesleyUPN -StartDate $startDate -EndDate $endDate
if ($sent) {
    $sent | Format-Table Received,RecipientAddress,Subject -AutoSize
} else {
    Write-Output "None found"
}

Write-Output "`n=== RECEIVED MESSAGES (last 3 days) ==="
$recv = Get-MessageTraceV2 -RecipientAddress $lesleyUPN -StartDate $startDate -EndDate $endDate
if ($recv) {
    $recv | Select-Object -First 20 | Format-Table Received,SenderAddress,Subject -AutoSize
} else {
    Write-Output "None found"
}

Write-Output "`n=== INBOX RULES ==="
$rules = Get-InboxRule -Mailbox $lesleyUPN
if ($rules) {
    $rules | Format-Table Name,Enabled,Description -AutoSize
} else {
    Write-Output "No inbox rules"
}

Write-Output "`n=== FORWARDING CONFIG ==="
Write-Output "ForwardingAddress: $($mbx.ForwardingAddress)"
Write-Output "ForwardingSmtpAddress: $($mbx.ForwardingSmtpAddress)"
Write-Output "DeliverToMailboxAndForward: $($mbx.DeliverToMailboxAndForward)"

Write-Output "`n=== FOLDER ITEM COUNTS ==="
Get-MailboxFolderStatistics -Identity $lesleyUPN | Where-Object { $_.ItemsInFolder -gt 0 } | Sort-Object ItemsInFolder -Descending | Select-Object -First 15 | Format-Table Name,FolderType,ItemsInFolder,FolderSize -AutoSize

Disconnect-ExchangeOnline -Confirm:$false
