Get Database Size for all SharePoint DBs via 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

 

 


Comments (4)
  1. Fábio says:

    Wow
    Thank you!!

  2. Richard Ericksen says:

    this is perfect, thank you so much!

  3. Jeff Joubert says:

    Excellent work. Thank you!

  4. Thomas Munoz says:

    Thanks a lot for this great script. copy & paste = works!

Comments are closed.

Skip to main content