$Date = Get-Date
$smtpServer = "smtp.domain.lan"
$smtpFrom = "WhiteSpace@domain.nl"
$smtpTo = "receipient@domain.nl"
$messageSubject = "WhiteSpace report for $Date"
$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$message.Subject = $messageSubject
$message.IsBodyHTML = $true
$a = "<style>"
$a = $a + "BODY{font-family: Arial; font-size: 10pt;}"
$a = $a + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$a = $a + "TH{border: 1px solid black; background: #dddddd; padding: 5px;}"
$a = $a + "TD{border: 1px solid black; padding: 5px;}"
$a = $a + "</style>"
$message.Body = Get-MailboxDatabase -Status | sort name | select name,@{Name='DB Size (Gb)';Expression={$_.DatabaseSize.ToGb()}},@{Name='Available New Mbx Space Gb)';Expression={$_.AvailableNewMailboxSpace.ToGb()}} | ConvertTo-Html -Head $a
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)
The result looks like this:
Run from the Task scheduler with this line:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\Bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; 'C:\_Scripts\Exchange\WhiteSpace.ps1'"