Sometimes I get asked by clients to check their Exchange server. Some tasks can be automated with EMS or Powershell if you add the Exchange Snapin. I put some commands together in a script to check the most basic things on a Exchange server. Here is the code:
# Clearing the Error Log $error.clear()
# Adding EMS module Add-PSSnapin microsoft.exchange.management.powershell.snapin
Install-Module -Name ExchangeOnlineManagement Import-Module ExchangeOnlineManagement; Get-Module ExchangeOnlineManagement Connect-ExchangeOnline
# Clearing the screen cls
# Check all URL Write-Host “——————————————-“ Write-Host “Getting information about URL’s” -ForegroundColor Green Write-Host “——————————————-“ Get-ExchangeServer | Get-ClientAccessService | fl identity, *ternaluri* Get-ExchangeServer | Get-EcpVirtualDirectory | fl Identity, *ternalurl* Get-ExchangeServer | Get-MapiVirtualDirectory | fl Identity, *ternalurl* Get-ExchangeServer | Get-OabVirtualDirectory | fl Identity, *ternalurl* Get-ExchangeServer | Get-OutlookAnywhere | fl Identity, *ternalhost*, *ticationmeth* Get-ExchangeServer | Get-OwaVirtualDirectory | fl Identity, *ternalurl* Get-ExchangeServer | Get-WebServicesVirtualDirectory | fl Identity, *ternalurl* Write-Host “” Write-Host “”
# Check all services Write-Host “——————————————-“ Write-Host “Check if the Exchange hervice health” -ForegroundColor Green Write-Host “——————————————-“ Test-ServiceHealth Write-Host “” Write-Host “”
# Check Monitoring Write-Host “——————————————-“ Write-Host “Check all Monitoring mailbox” -ForegroundColor Green Write-Host “——————————————-“ $mon=(get-mailbox -Monitoring).Count Write-Host “” Write-Host “There are a total of $mon Monitoring mailbox’es:” -ForegroundColor Yellow get-mailbox -Monitoring | Format-Table DisplayName, ServerName, Database, WhenCreated | out-string
# Check Arbitration mailbox Write-Host “——————————————-“ Write-Host “Check all Arbitration mailbox’es” -ForegroundColor Green Write-Host “——————————————-“ $arb=(get-mailbox -Arbitration).Count Write-Host “” Write-Host “There are a total of $arb Arbitration mailbox’es:” -ForegroundColor Yellow get-mailbox -Arbitration | out-string
# Check AuditLog Write-Host “——————————————-“ Write-Host Checking AuditLog” -ForegroundColor Green Write-Host “——————————————-“ get-mailbox -AuditLog | out-string Write-Host “” Write-Host “”
# Looking for on-prem mailbox’es Write-Host “——————————————-“ Write-Host “Looking for on-prem mailbox’es” -ForegroundColor Green Write-Host “——————————————-“ $mailb=(get-mailbox).count Write-Host “” Write-Host “There are a total of $mailb mailbox’es:” -ForegroundColor Yellow Get-Mailbox | Format-Table Name, ServerName, Database Write-Host “” Write-Host “”
# Getting information about on-prem databases Write-Host “——————————————-“ Write-Host “Checking databases that are mounted” -ForegroundColor Green Write-Host “——————————————-“ $db=(Get-MailboxDatabase).Count Write-Host “” Write-Host “There are a total of $db databases:” -ForegroundColor Yellow Get-MailboxDatabase -status | format-table name, mounted, server, recovery
Write-Host “” Write-Host “” # Getting info about DAG Write-Host “——————————————-“ Write-Host “Showing information about the DAG” -ForegroundColor Green Write-Host “——————————————-“ Write-Host “” Get-DatabaseAvailabilityGroup | Format-Table Name, Servers, WitnessServer, OriginatingServer
Write-Host “” Write-Host “” # Checking MAPI Write-Host “——————————————-“ Write-Host “Testing MAPI” -ForegroundColor Green Write-Host “——————————————-“ Test-MAPIConnectivity
Write-Host “” Write-Host “” # Checking queues Write-Host “——————————————-“ Write-Host “Checking the queues” -ForegroundColor Green Write-Host “——————————————-“ Get-Queue | format-table
Write-Host “” Write-Host “” # Checking SMTP connectors Write-Host “——————————————-“ Write-Host “Checking the SMTP connectors” -ForegroundColor Green Write-Host “——————————————-“ Test-SMTPConnectivity | out-string
Write-Host “” Write-Host “” # Quick check to see if mail can be sendt Write-Host “——————————————-“ Write-Host “Quick check to see if mail can be sendt” -ForegroundColor Green Write-Host “——————————————-“ Test-Mailflow
Write-Host “” Write-Host “” Write-Host “——————————————-“ Write-Host “Tesing is complete” -ForegroundColor Yellow Write-Host “——————————————-“
# This script is finished
Comments