Get Exchange 2013 Database and Whitespace values.

In organisations that are still using Exchange 2013, you may want to be able to differentiate between the actual size of your databases and the whitespace provisioned for your databases to use.

The below PowerShell script can be added as a Scheduled Task in order to notify your Infrastructure teams.

# This script will take the database sizes from exchange and email them to a mail address.
# First we import the exchange module.

$ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<SMTPServer>/PowerShell
Import-PSSession $ExchangeSession

# Creating our array to allow string and output of command into subject.
$string = “<Org> Database Sizes – ”
$Date = (Get-Date)
$SMTPSubject =  $string + $date

# Factor in the variables for the Send-MailMessage command.

$SMTPTo = “emailrecipient@domain”
$SMTPFrom = “emailsender@domain”
$SMTPServer = “<SMTPServer>”
$SmtpBody = Get-MailboxDatabase -Status | select name, databasesize, AvailableNewMailboxSpace | Sort-Object Name | Out-String

# Then output that into a mail message.

Send-MailMessage -SmtpServer $SMTPServer -From $SMTPFrom -To $SMTPTo -Body $SmtpBody -subject $SMTPSubject