gangstanthony

calculate_size_difference_of_database_daily

May 3rd, 2016
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # https://www.reddit.com/r/PowerShell/comments/4hnhh8/calculate_size_difference_of_database_daily/
  2.  
  3. $dbInfo = Get-SPDatabase | ForEach-Object {
  4.     # get db server
  5.     if (!($_.Server.Address)) {
  6.         $dbserver = $_.Server
  7.     } else {
  8.         $dbserver = $_.Server.Address
  9.     }
  10.  
  11.     # Find if there exists a database today with a name matching a database from the previous day
  12.     if ($lastSPDatabases) {
  13.         if ($lastSPDatabases."DB Name" -eq $_.Name) {
  14.             $sizediff = $_.DiskSizeRequired - $($lastSPDatabases | Where-Object {$_."DB Name" -eq $_.Name}).DiskSizeRequired
  15.             # Size is in GB
  16.             if ($sizediff -gt 1073741824) {
  17.                 $growth = [math]::Round($sizediff/1gb,2).ToString() + " GB"
  18.             } else { # Size is in MB
  19.                 $growth = [math]::Round($sizediff/1mb,2).ToString() + " MB"
  20.             } #/else
  21.         }
  22.     }
  23.  
  24.     [PSCustomObject]@{
  25.         "DB Name" = $_.Name
  26.         "DB Server" = $dbserver
  27.         WebApp = $_.WebApplication.DisplayName
  28.         "WebApp URL" = $_.WebApplication.Url
  29.         SiteCount = $_.CurrentSiteCount
  30.         Growth = $growth
  31.         Type = $_.Type
  32.         DiskSizeRequired = $_.DiskSizeRequired
  33.     } #/PSCustomObject
  34. } #/ForEach-Object
Add Comment
Please, Sign In to add comment