Get-DbaDbMailHistory
View SourceSynopsis
Retrieves Database Mail history from SQL Server’s msdb database for troubleshooting and compliance
Description
Retrieves comprehensive Database Mail history from the msdb.dbo.sysmail_allitems table, including delivery status, recipients, subject lines, and timestamps. This function helps DBAs troubleshoot email delivery issues, audit mail activity for compliance reporting, and monitor Database Mail performance. You can filter results by send date or delivery status (Sent, Failed, Unsent, Retrying) to focus on specific timeframes or problem emails.
Syntax
Get-DbaDbMailHistory
[[-SqlInstance] <DbaInstanceParameter[]>]
[[-SqlCredential] <PSCredential>]
[[-Since] <DateTime>]
[[-Status] <String>]
[-EnableException]
[<CommonParameters>]
Examples
Example: 1
PS C:\> Get-DbaDbMailHistory -SqlInstance sql01\sharepoint
Returns the entire DBMail history on sql01\sharepoint
Example: 2
PS C:\> Get-DbaDbMailHistory -SqlInstance sql01\sharepoint | Select-Object *
Returns the entire DBMail history on sql01\sharepoint then return a bunch more columns
Example: 3
PS C:\> $servers = "sql2014","sql2016", "sqlcluster\sharepoint"
PS C:\> $servers | Get-DbaDbMailHistory
Returns the all DBMail history for “sql2014”,“sql2016” and “sqlcluster\sharepoint”
Optional Parameters
-SqlInstance
The target SQL Server instance or instances.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | true (ByValue) |
| Default Value |
-SqlCredential
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value |
-Since
Filters mail history to only include emails sent after the specified date and time.
Use this when troubleshooting recent delivery issues or generating reports for specific time periods.
Accepts standard PowerShell DateTime objects like (Get-Date).AddDays(-7) for the past week.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value |
-Status
Filters results to only show emails with the specified delivery status.
Use ‘Failed’ to identify delivery problems, ‘Unsent’ for queued messages, or ‘Retrying’ for current retry attempts.
Accepts multiple values: Unsent, Sent, Failed, and Retrying.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value | |
| Accepted Values | Unsent,Sent,Failed,Retrying |
-EnableException
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with “sea of red” exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this “nice by default” feature off and enables you to catch exceptions with your own try/catch.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value | False |
dbatools