Get Database Size for all SharePoint Data Bases using PowerShell


Add-PSSnapin microsoft.sharepoint.powershell

$size = 0

foreach ($db in Get-SPContentDatabase)

{

$size = $size + $db.DiskSizeRequired

}

$cdbs = “{0:N2}” -f($size/1gb)

$ssa = Get-SPEnterpriseSearchServiceApplication

$topo = $ssa | Get-SPEnterpriseSearchTopology  -Active

$indexcomponent = (Get-SPEnterpriseSearchComponent -SearchTopology $topo | ?{$_.name -like “*index*”})[0]

$folder = $indexcomponent.RootDirectory

$indexsize = “{0:N2}” -f ((Get-ChildItem $folder -Recurse | Measure-Object -sum  Length).sum/1GB)

$dbs = Get-SPDatabase

cls

write-host “————————————————————————————–” -fore green

Get-Date

write-host “”

write-host “————————————————————————————–” -fore green

write-host “SUM: Content DB Size in GB: ” -NoNewline -fore White

write-host $cdbs -fore Yellow

write-host “————————————————————————————–” -fore green

write-host “Index Size (Localhost) on Disk in GB: “-NoNewline -fore white

write-host $indexsize -fore Yellow

write-host “————————————————————————————–” -fore green

$sum_all_dbs = 0

foreach ($db in $dbs)

{

write-host $db.name “DB Size in GB: ” -NoNewline -fore White

$dsr = “{0:N2}” -f ($db.DiskSizeRequired/1gb)

write-host $dsr  -fore Yellow

$sum_all_dbs=$sum_all_dbs+$db.DiskSizeRequired

}

write-host “————————————————————————————–” -fore green

write-host “SUM: Usage of all SharePoint DBs in GB: ” -NoNewline -fore White

$sum_all_dbs = “{0:N2}” -f ($sum_all_dbs/1gb)

write-host $sum_all_dbs -fore Yellow

write-host “————————————————————————————–” -fore green

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s