Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # https://www.reddit.com/r/PowerShell/comments/4hnhh8/calculate_size_difference_of_database_daily/
- $dbInfo = Get-SPDatabase | ForEach-Object {
- # get db server
- if (!($_.Server.Address)) {
- $dbserver = $_.Server
- } else {
- $dbserver = $_.Server.Address
- }
- # Find if there exists a database today with a name matching a database from the previous day
- if ($lastSPDatabases) {
- if ($lastSPDatabases."DB Name" -eq $_.Name) {
- $sizediff = $_.DiskSizeRequired - $($lastSPDatabases | Where-Object {$_."DB Name" -eq $_.Name}).DiskSizeRequired
- # Size is in GB
- if ($sizediff -gt 1073741824) {
- $growth = [math]::Round($sizediff/1gb,2).ToString() + " GB"
- } else { # Size is in MB
- $growth = [math]::Round($sizediff/1mb,2).ToString() + " MB"
- } #/else
- }
- }
- [PSCustomObject]@{
- "DB Name" = $_.Name
- "DB Server" = $dbserver
- WebApp = $_.WebApplication.DisplayName
- "WebApp URL" = $_.WebApplication.Url
- SiteCount = $_.CurrentSiteCount
- Growth = $growth
- Type = $_.Type
- DiskSizeRequired = $_.DiskSizeRequired
- } #/PSCustomObject
- } #/ForEach-Object
Add Comment
Please, Sign In to add comment