# Script to move all system mailboxes and remove excess HealthMailboxes CLS Write-host '######################################' -ForegroundColor Green Write-host '# ' -ForegroundColor Green -NoNewLine Write-host 'System / Non-Primary Mailbox Check' -ForegroundColor White -NoNewLine Write-host ' #' -ForegroundColor Green Write-host '######################################' -ForegroundColor Green Write-Host ' ' Write-Host ' ' # Pause for a sec # start-Sleep 4 ## Script Body ## Write-host 'Which Exchange Server do you want to check' -ForegroundColor Yellow -NoNewLine Write-host " for mailboxes? ('d' - default or enter name) " -ForegroundColor Yellow -NoNewLine $Answer = Read-host If ($Answer -eq 'd') { # Server Name Check $ExchangeServer = $Env:ComputerName $AllServers = (Get-ExchangeServer).name If ($AllServers -Contains $ExchangeServer){ $ExServer = $ExchangeServer } Else { Write-host "Error - this is not an Exchange Server!" -ForegroundColor Red } } Else { # Server Name Check $AllServers = (Get-ExchangeServer).name If ($AllServers -Contains $Answer){ $ExServer = $Answer } Else { Write-host "Error - this is not an Exchange Server!" -ForegroundColor Red } } Write-host " " Write-host " " Write-host "Checking the Exchange Server $ExServer for mailboxes now...." -ForegroundColor Yellow Write-host " " # Mailbox Check $ArbitrationMailboxes = Get-Mailbox -Arbitration -Server $ExServer | Select-Object Name,ServerName $ArchiveMailboxes = Get-Mailbox -Archive -Server $ExServer | Select-Object Name,ServerName $AuditLogMailboxes = Get-Mailbox -AuditLog -Server $ExServer | Select-Object Name,ServerName $AuxAuditLogMailboxes = Get-Mailbox -AuxAuditLog -Server $ExServer | Select-Object Name,ServerName $MigrationMailboxes = Get-Mailbox -Migration -Server $ExServer | Select-Object Name,ServerName $MonitoringMailboxes = Get-Mailbox -Monitoring -Server $ExServer | Select-Object Name,ServerName $PublicFolderMailboxes = Get-Mailbox -PublicFolder -Server $ExServer | Select-Object Name,ServerName # ARBITRATION MAILBOX CHECK: # -------------------------- If ($Null -ne $ArbitrationMailboxes) { Write-Host "Arbitration " -ForegroundColor Green -NoNewLine Write-host "mailboxes found:" -ForegroundColor White Write-host "------------------------------" -ForegroundColor White Write-host "Name,Server,Type" Foreach($Mailbox in $ArbitrationMailboxes) { $Server = $Mailbox.ServerName $Mbx = $Mailbox.Name write-host "$Mbx,$Server,Arbitration" } } Else { Write-host "No " -ForegroundColor White -NoNewLine Write-Host "Arbitration " -ForegroundColor Green -NoNewLine Write-host "mailboxes found" -ForegroundColor White } # Archive MAILBOX CHECK: # -------------------------- If ($Null -ne $ArchiveMailboxes) { Write-Host "" Write-Host "Archive " -ForegroundColor Green -NoNewLine Write-host "mailboxes found:" -ForegroundColor White Write-host "------------------------------" -ForegroundColor White Write-host "Name,Server,Type" Foreach($Mailbox in $ArchiveMailboxes) { $Server = $Mailbox.ServerName $Mbx = $Mailbox.Name write-host "$Mbx,$Server,Archive" } Write-Host "" } Else { Write-host "No " -ForegroundColor White -NoNewLine Write-Host "Archive " -ForegroundColor Green -NoNewLine Write-host "mailboxes found" -ForegroundColor White } # AuditLog MAILBOX CHECK: # -------------------------- If ($Null -ne $AuditLogMailboxes) { Write-Host "" Write-Host "AuditLog " -ForegroundColor Green -NoNewLine Write-host "mailboxes found:" -ForegroundColor White Write-host "------------------------------" -ForegroundColor White Write-host "Name,Server,Type" Foreach($Mailbox in $AuditLogMailboxes) { $Server = $Mailbox.ServerName $Mbx = $Mailbox.Name write-host "$Mbx,$Server,AuditLog" } Write-Host "" } Else { Write-host "No " -ForegroundColor White -NoNewLine Write-Host "AuditLog " -ForegroundColor Green -NoNewLine Write-host "mailboxes found" -ForegroundColor White } # AuxAuditLog MAILBOX CHECK: # -------------------------- If ($Null -ne $AuxAuditLogMailboxes) { Write-Host "" Write-Host "AuxAuditLog " -ForegroundColor Green -NoNewLine Write-host "mailboxes found:" -ForegroundColor White Write-host "------------------------------" -ForegroundColor White Write-host "Name,Server,Type" Foreach($Mailbox in $AuxAuditLogMailboxes) { $Server = $Mailbox.ServerName $Mbx = $Mailbox.Name write-host "$Mbx,$Server,AuxAuditLog" } Write-Host "" } Else { Write-host "No " -ForegroundColor White -NoNewLine Write-Host "AuxAuditLog " -ForegroundColor Green -NoNewLine Write-host "mailboxes found" -ForegroundColor White } # Migration MAILBOX CHECK: # -------------------------- If ($Null -ne $MigrationMailboxes) { Write-Host "" Write-Host "Migration " -ForegroundColor Green -NoNewLine Write-host "mailboxes found:" -ForegroundColor White Write-host "------------------------------" -ForegroundColor White Write-host "Name,Server,Type" Foreach($Mailbox in $MigrationMailboxes) { $Server = $Mailbox.ServerName $Mbx = $Mailbox.Name write-host "$Mbx,$Server,Migration" } Write-Host "" } Else { Write-host "No " -ForegroundColor White -NoNewLine Write-Host "Migration " -ForegroundColor Green -NoNewLine Write-host "mailboxes found" -ForegroundColor White } # Monitoring MAILBOX CHECK: # -------------------------- If ($Null -ne $MonitoringMailboxes) { Write-Host "" Write-Host "Monitoring " -ForegroundColor Green -NoNewLine Write-host "mailboxes found:" -ForegroundColor White Write-host "------------------------------" -ForegroundColor White Write-host "Name,Server,Type" Foreach($Mailbox in $MonitoringMailboxes) { $Server = $Mailbox.ServerName $Mbx = $Mailbox.Name write-host "$Mbx,$Server,Monitoring" } Write-Host "" } Else { Write-host "No " -ForegroundColor White -NoNewLine Write-Host "Monitoring " -ForegroundColor Green -NoNewLine Write-host "mailboxes found" -ForegroundColor White } # PublicFolder MAILBOX CHECK: # -------------------------- If ($Null -ne $PublicFolderMailboxes) { Write-Host "" Write-Host "PublicFolder " -ForegroundColor Green -NoNewLine Write-host "mailboxes found:" -ForegroundColor White Write-host "------------------------------" -ForegroundColor White Write-host "Name,Server,Type" Foreach($Mailbox in $PublicFolderMailboxes) { $Server = $Mailbox.ServerName $Mbx = $Mailbox.Name write-host "$Mbx,$Server,PublicFolder" } Write-Host "" } Else { Write-host "No " -ForegroundColor White -NoNewLine Write-Host "PublicFolder " -ForegroundColor Green -NoNewLine Write-host "mailboxes found" -ForegroundColor White }