If you're Exchange admin and you're also responsible for Office365 tenant, at some point you would like to know if some (or many) messages are stuck in the submission queue. I've had a lot of headaches during migration to Office365 and I've used simple powershell script to prevent queue overflow and to reduce time needed for recovery.
Misconfigured receive connector, expired certificate or network connectivity issue are the main reasons for such behaviour. Using this script in production can only help you to minimize impact on your mail flow (NDRs, DSNs etc...) and to react before users even notice that something isn't right.
#Office365 Session Arguments
$user = '[email protected]'
$password = 'comPl3xpA66w0rd'
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist @($user,(ConvertTo-SecureString -String $password -AsPlainText -Force))
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $credentials -Authentication Basic -AllowRedirection
Import-PSSession $Session
#Defining time range for checks
$startdate = (Get-Date).AddDays(-1)
$enddate = (Get-Date)
# Getting the results
$results = Get-MessageTrace -StartDate $startdate -EndDate $enddate | Where-Object {$_.status -eq "Pending"}
$body = $results | Select-Object Received,SenderAddress,RecipientAddress,Subject,Status,FromIP,Size | ConvertTo-Html -Head $a | Out-String
#Prevent alerts for false positive matches (for less than 5 messages)
$check= $results | measure-object | Select-Object Count
If ($check.count -le 5)
{
echo "everything is fine, nothing to worry about"
}
Else {
#HTML Enhancements for email report
$a = "<style>"
$a = $a + "BODY{background-color:FFFFFF;font-family:'Segoe UI', Calibri, sans-serif;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:DeepPink}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:FFFFFF}"
$a = $a + "</style>"
Send-mailmessage -from "Office365-MailReports <[email protected]>" -to "[email protected]" -BodyAsHtml -subject "EO Messages are stuck in the transport queue!" -body $body -priority High -smtpServer serverfqdn
}
Remove-PSSession $Session
Misconfigured receive connector, expired certificate or network connectivity issue are the main reasons for such behaviour. Using this script in production can only help you to minimize impact on your mail flow (NDRs, DSNs etc...) and to react before users even notice that something isn't right.
#Office365 Session Arguments
$user = '[email protected]'
$password = 'comPl3xpA66w0rd'
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist @($user,(ConvertTo-SecureString -String $password -AsPlainText -Force))
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $credentials -Authentication Basic -AllowRedirection
Import-PSSession $Session
#Defining time range for checks
$startdate = (Get-Date).AddDays(-1)
$enddate = (Get-Date)
# Getting the results
$results = Get-MessageTrace -StartDate $startdate -EndDate $enddate | Where-Object {$_.status -eq "Pending"}
$body = $results | Select-Object Received,SenderAddress,RecipientAddress,Subject,Status,FromIP,Size | ConvertTo-Html -Head $a | Out-String
#Prevent alerts for false positive matches (for less than 5 messages)
$check= $results | measure-object | Select-Object Count
If ($check.count -le 5)
{
echo "everything is fine, nothing to worry about"
}
Else {
#HTML Enhancements for email report
$a = "<style>"
$a = $a + "BODY{background-color:FFFFFF;font-family:'Segoe UI', Calibri, sans-serif;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:DeepPink}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:FFFFFF}"
$a = $a + "</style>"
Send-mailmessage -from "Office365-MailReports <[email protected]>" -to "[email protected]" -BodyAsHtml -subject "EO Messages are stuck in the transport queue!" -body $body -priority High -smtpServer serverfqdn
}
Remove-PSSession $Session