Most of the administrators will have a task to prepare daily server health report which includes Disk space, Server Events, Database Status and Backup Status.
This script will help administrators to generate a Backup status report for their day to day job. They can automate this script to run daily basis. We can customize the threshold for each parameter like EDB size, White Space and number of days the backup is not running. We can disable email function if somebody wants to have the report only in HTML file. It will also give the no.of mailboxes from each database.
Script Block
# Beginning of the script
###############################################################################################
#
# Generate Backup Report of all Exchange Servers and send email.
# If you dont want the email function, then it will just generate a HTML file.
# Script will give you a warnings based on the threshold set.
# We can use this script to pull a Backup report from Exchange 2010 and 2013 servers with DAG.
# Script will fetch only the active databases from each server and give the details.
# # How to Run the script
# 1. Set the threshold as per your need
# 2. If you want to send the report as email, Give $Mail = "True" else give $Mail = "False"
# 3. Run the script
# Date: 03/27/2015
# Not added any error checking into this script yet.
#
###############################################################################################
# Thresholds
$EDB = "100 GB"
$WSpace = "15 GB"
$Seven = (get-date).addHours(-168)
$One = (get-date).addHours(-24)
# Inputs for Email
$Subject = "Backup Report"
$FromAddress = "BackupReport@testlab.com"
$ToAddress = "admin@testlab.com"
$Relay = "SMTP relay server FQDN"
$SMTPClient = New-Object System.Net.Mail.smtpClient
$MailMessage = New-Object System.Net.Mail.MailMessage
# Mail Function
$Mail = "True"
# Main Function
Set-ADServerSettings -ViewEntireForest $True
$MailSend = $null
$body = $null
$body += '<!--mce:0-->'
$body += '</head>'
$body += '<body>'
$body += "<p class=`"header`" align='center'><strong>Exchange Servers Backup Report : " + $(get-date).toshortdatestring() + " @ " + $(get-date).ToshorttimeString()
Get-MailboxServer -ResultSize Unlimited | Sort Name | %{
$excServerName = $_.name
$bkp = Get-MailboxDatabase -Server $excServerName -Status | Sort Name | ?{($_.MountedOnServer -Match $excServerName )}
if($bkp -ne $null)
{
#Table Header
$body += '<table width=65% align=center>'
$body += '<tr><td colspan=6 align=center style="background-color: #DCDCDC" border: 1 Groove white; ><p class="table" style="color: white"><strong><font color= Black><b>' + ($excServerName).toupper() + '</b></font></strong></td></p></tr>'
#Cloumn Header
$body += '<tr><td align="Center" style="background-color: #483D8B" width="11%" border: 1 Groove white;><p class="table" style="color: white"><b>Database</b></p></td>'
$body += '<td align="Center" style="background-color: #483D8B" width="10%" border: 1 Groove white;><p class="table" style="color: white"><b>EDB Size</b></p></td>'
$body += '<td align="Center" style="background-color: #483D8B" width="10%" border: 1 Groove white;><p class="table" style="color: white"><b>White Space</b></p></td>'
$body += '<td align="Center" style="background-color: #483D8B" width="12%" border: 1 Groove white;><p class="table" style="color: white"><b>Last Full Backup</b></p></td>'
$body += '<td align="Center" style="background-color: #483D8B" width="12%" border: 1 Groove white;><p class="table" style="color: white"><b>Last Incr Backup</b></p></td>'
$body += '<td align="Center" style="background-color: #483D8B" width="10%" border: 1 Groove white;><p class="table" style="color: white"><b>Mailbox Count</b></p></td></tr>'
$bkp | foreach {
$mbxcount = $null
$DBS = $null
$WHS =$null
$mbxcount = (Get-Mailbox -Database $_.Identity -ResultSize Unlimited).Count
[String]$DBS = $_.DatabaseSize
$EDBSize = $DBS.split('(')[0]
[String]$WHS = $_.AvailableNewMailboxSpace
$WS = $WHS.Split('(')[0]
$body += '<tr><td align="Center" border: 1 Groove white;>' + $_.Identity + "</td>"
if ($_.DatabaseSize -ge $EDB){
$body += '<td align="Center" border: 1 Groove white; bgcolor="FFCC66">' + $EDBSize + "</td>" }
else{
$body += '<td align="Center" border: 1 Groove white;>' + $EDBSize + "</td>" }
if ($_.AvailableNewMailboxSpace -ge $WSpace){
$body += '<td align="Center" border: 1 Groove white; bgcolor="FFCC66">' + $WS + "</td>" }
else{
$body += '<td align="Center" border: 1 Groove white;>' + $WS + "</td>" }
if ($_.LastFullBackup -ge $Seven){
$body += '<td align="Center" border: 1 Groove white;>' + $_.LastFullBackup + "</td>" }
else{
$body += '<td align="Center" border: 1 Groove white; bgcolor="FFCC66">' + $_.LastFullBackup + "</td>" }
if (($_.LastIncrementalBackup -ge $One) -or ($_.LastFullBackup -ge $One)){
$body += '<td align="Center" border: 1 Groove white;>' + $_.LastIncrementalBackup + "</td>" }
else{
$body += '<td align="Center" border: 1 Groove white; bgcolor="FFCC66">' + $_.LastIncrementalBackup + "</td>" }
$body += '<td align="Center" border: 1 Groove white;>' + $mbxcount + "</td></tr>"
}
$body += '</table><br>'
$bkp
}
}
if ($Mail -eq "True")
{
$body += "Report Completed"
$body += '</p></body></html>'
##############################################################
$MailMessage.Subject = "$Subject"
$MailMessage.Body = "$Body"
$MailMessage.sender = "$FromAddress"
$MailMessage.From = "$FromAddress"
$MailMessage.To.add("$ToAddress")
#$MailMessage.CC.add("$CCAddress")
#$MailMessage.CC.add("$CCAddress2")
$MailMessage.IsBodyHTML = $True
$smtpclient.host = "$Relay"
$smtpclient.send($MailMessage)
##############################################################
}
else
{
$Date = get-date
$FileName = 'Backup_Report'
$FileName += $date.year.tostring()
$FileName += $date.month.tostring()
$FileName += $date.day.tostring()
$FileName += '.html'
$body += "Report Completed"
$body += '</p></body></html>'
set-content $FileName -value $body
}
# End of the Script
Sample output
This script will help administrators to generate a Backup status report for their day to day job. They can automate this script to run daily basis. We can customize the threshold for each parameter like EDB size, White Space and number of days the backup is not running. We can disable email function if somebody wants to have the report only in HTML file. It will also give the no.of mailboxes from each database.
Script Block
# Beginning of the script
###############################################################################################
#
# Generate Backup Report of all Exchange Servers and send email.
# If you dont want the email function, then it will just generate a HTML file.
# Script will give you a warnings based on the threshold set.
# We can use this script to pull a Backup report from Exchange 2010 and 2013 servers with DAG.
# Script will fetch only the active databases from each server and give the details.
# # How to Run the script
# 1. Set the threshold as per your need
# 2. If you want to send the report as email, Give $Mail = "True" else give $Mail = "False"
# 3. Run the script
# Date: 03/27/2015
# Not added any error checking into this script yet.
#
###############################################################################################
# Thresholds
$EDB = "100 GB"
$WSpace = "15 GB"
$Seven = (get-date).addHours(-168)
$One = (get-date).addHours(-24)
# Inputs for Email
$Subject = "Backup Report"
$FromAddress = "BackupReport@testlab.com"
$ToAddress = "admin@testlab.com"
$Relay = "SMTP relay server FQDN"
$SMTPClient = New-Object System.Net.Mail.smtpClient
$MailMessage = New-Object System.Net.Mail.MailMessage
# Mail Function
$Mail = "True"
# Main Function
Set-ADServerSettings -ViewEntireForest $True
$MailSend = $null
$body = $null
$body += '<!--mce:0-->'
$body += '</head>'
$body += '<body>'
$body += "<p class=`"header`" align='center'><strong>Exchange Servers Backup Report : " + $(get-date).toshortdatestring() + " @ " + $(get-date).ToshorttimeString()
Get-MailboxServer -ResultSize Unlimited | Sort Name | %{
$excServerName = $_.name
$bkp = Get-MailboxDatabase -Server $excServerName -Status | Sort Name | ?{($_.MountedOnServer -Match $excServerName )}
if($bkp -ne $null)
{
#Table Header
$body += '<table width=65% align=center>'
$body += '<tr><td colspan=6 align=center style="background-color: #DCDCDC" border: 1 Groove white; ><p class="table" style="color: white"><strong><font color= Black><b>' + ($excServerName).toupper() + '</b></font></strong></td></p></tr>'
#Cloumn Header
$body += '<tr><td align="Center" style="background-color: #483D8B" width="11%" border: 1 Groove white;><p class="table" style="color: white"><b>Database</b></p></td>'
$body += '<td align="Center" style="background-color: #483D8B" width="10%" border: 1 Groove white;><p class="table" style="color: white"><b>EDB Size</b></p></td>'
$body += '<td align="Center" style="background-color: #483D8B" width="10%" border: 1 Groove white;><p class="table" style="color: white"><b>White Space</b></p></td>'
$body += '<td align="Center" style="background-color: #483D8B" width="12%" border: 1 Groove white;><p class="table" style="color: white"><b>Last Full Backup</b></p></td>'
$body += '<td align="Center" style="background-color: #483D8B" width="12%" border: 1 Groove white;><p class="table" style="color: white"><b>Last Incr Backup</b></p></td>'
$body += '<td align="Center" style="background-color: #483D8B" width="10%" border: 1 Groove white;><p class="table" style="color: white"><b>Mailbox Count</b></p></td></tr>'
$bkp | foreach {
$mbxcount = $null
$DBS = $null
$WHS =$null
$mbxcount = (Get-Mailbox -Database $_.Identity -ResultSize Unlimited).Count
[String]$DBS = $_.DatabaseSize
$EDBSize = $DBS.split('(')[0]
[String]$WHS = $_.AvailableNewMailboxSpace
$WS = $WHS.Split('(')[0]
$body += '<tr><td align="Center" border: 1 Groove white;>' + $_.Identity + "</td>"
if ($_.DatabaseSize -ge $EDB){
$body += '<td align="Center" border: 1 Groove white; bgcolor="FFCC66">' + $EDBSize + "</td>" }
else{
$body += '<td align="Center" border: 1 Groove white;>' + $EDBSize + "</td>" }
if ($_.AvailableNewMailboxSpace -ge $WSpace){
$body += '<td align="Center" border: 1 Groove white; bgcolor="FFCC66">' + $WS + "</td>" }
else{
$body += '<td align="Center" border: 1 Groove white;>' + $WS + "</td>" }
if ($_.LastFullBackup -ge $Seven){
$body += '<td align="Center" border: 1 Groove white;>' + $_.LastFullBackup + "</td>" }
else{
$body += '<td align="Center" border: 1 Groove white; bgcolor="FFCC66">' + $_.LastFullBackup + "</td>" }
if (($_.LastIncrementalBackup -ge $One) -or ($_.LastFullBackup -ge $One)){
$body += '<td align="Center" border: 1 Groove white;>' + $_.LastIncrementalBackup + "</td>" }
else{
$body += '<td align="Center" border: 1 Groove white; bgcolor="FFCC66">' + $_.LastIncrementalBackup + "</td>" }
$body += '<td align="Center" border: 1 Groove white;>' + $mbxcount + "</td></tr>"
}
$body += '</table><br>'
$bkp
}
}
if ($Mail -eq "True")
{
$body += "Report Completed"
$body += '</p></body></html>'
##############################################################
$MailMessage.Subject = "$Subject"
$MailMessage.Body = "$Body"
$MailMessage.sender = "$FromAddress"
$MailMessage.From = "$FromAddress"
$MailMessage.To.add("$ToAddress")
#$MailMessage.CC.add("$CCAddress")
#$MailMessage.CC.add("$CCAddress2")
$MailMessage.IsBodyHTML = $True
$smtpclient.host = "$Relay"
$smtpclient.send($MailMessage)
##############################################################
}
else
{
$Date = get-date
$FileName = 'Backup_Report'
$FileName += $date.year.tostring()
$FileName += $date.month.tostring()
$FileName += $date.day.tostring()
$FileName += '.html'
$body += "Report Completed"
$body += '</p></body></html>'
set-content $FileName -value $body
}
# End of the Script
Sample output
No comments:
Post a Comment