Advertisement
Acquira

Small_DB_Indexing_Report

Sep 2nd, 2021
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Connect to Exchange
  2. . 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'
  3. Connect-ExchangeServer -auto
  4. clear
  5.  
  6. $today = Get-Date -Format yyyy_MM_dd
  7. #Path to store the rport
  8. $filepath = "\\server\reports\$today`_Indexing.html"
  9.  
  10. #Get DB info
  11. $dbstatus = Get-MailboxDatabaseCopyStatus
  12.  
  13. #Start of the HTML file
  14. $html_header = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  15. <html xmlns="http://www.w3.org/1999/xhtml">
  16. <head>
  17. <style>
  18. table, th, td {
  19.  border: 2px solid black;
  20.  border-collapse: collapse;
  21. }
  22. th, td {
  23.  padding: 10px;
  24. }
  25. </style>
  26. <title>HTML TABLE</title>
  27. </head><body>
  28. <table>
  29. <thead><tr><th>Name</th><th>Status</th><th>Indexing</th><th>Available Space</th><th>Free Disk Percent</th><th>Disk Free Space</th><th>Total Space</th><th>Volume</th><th>Disk Name</th></tr></thead>
  30. <tbody>'
  31.  
  32. #Color code for easy to read informations
  33. $enabled= 'background-color:#00FF00'
  34. $warning = 'background-color:#FF0000'
  35. $info = 'background-color:#FFFF00'
  36.  
  37. #Generate table row for each DB
  38. $body = ""
  39. $dbstatus | % {
  40.    
  41.     $space = Get-MailboxDatabase -Status $_.DatabaseName  | select -ExpandProperty AvailableNewMailboxSpace
  42.     $space_to_string = $space.ToSTring().Split('(')[0]
  43.    
  44.     #Warning Treshold : 20GB
  45.     if($space.ToGB() -lt 20){
  46.         $available_space = "<td style=`"$disable`">$space</td>"
  47.     }
  48.    
  49.     #Notification treshold : 100GB
  50.     elseif($space.ToGB() -lt 100){
  51.         $available_space = "<td style=`"$info`">$space</td>"
  52.     }
  53.     else{
  54.         $available_space = "<td>$space</td>"
  55.     }
  56.  
  57.     #Check if DB status is Healthy
  58.     if($_.ContentIndexState -like "Healthy"){
  59.         $Indexing= "<td style=`"$enabled`">$($_.ContentIndexState)</td>"
  60.     }
  61.     else{
  62.         $Indexing= "<td style=`"$warning`">$($_.ContentIndexState)</td>"
  63.     }
  64.     #Check DB free space
  65.     #Warning Treshold : 1%
  66.     if($_.DiskFreeSpacePercent -le 1){
  67.         $FreePercent= "<td style=`"$warning`">$($_.DiskFreeSpacePercent)</td>"
  68.         $free_space = $_.DiskFreeSpace.ToString().Split('(')[0]
  69.         $FreeSpace= "<td style=`"$warning`">$free_space</td>"
  70.     }
  71.     else{
  72.         $FreePercent= "<td style=`"$enabled`">$($_.DiskFreeSpacePercent)</td>"
  73.         $free_space = $_.DiskFreeSpace.ToString().Split('(')[0]
  74.         $FreeSpace= "<td style=`"$enabled`">$free_space</td>"
  75.     }
  76.  
  77.     $ex_name = $_.Name.Split('\')[0]
  78.     $name = "<tr><td>$ex_name</td>"
  79.     $Copy= "<td>$($_.Status)</td>"
  80.     $total_space = $_.DiskTotalSpace.ToString().Split('(')[0]
  81.     $TotalSpace= "<td>$total_space</td>"
  82.     $DBMount = "<td>$($_.DatabaseVolumeMountPoint)</td>"
  83.     $db_name = $_.DatabaseVolumeName.split("{}")[1]
  84.     $DBName= "<td>$db_name</td></tr>`n"
  85.     $body+=$name+$Copy+$Indexing+$available_space+$FreePercent+$FreeSpace+$TotalSpace+$DBMount+$DBName
  86. }
  87. #End of HTML file
  88. $eof = "</tbody></table>
  89. </body></html>"
  90. $body += $eof
  91.  
  92. #Concatenate the full HTML file
  93. $html_file = $html_header + $body
  94. $html_file | Out-File -FilePath $filepath
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement