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
- Anonymous
September 10, 2015
Thanks a lot for this great script. copy & paste = works! - Anonymous
June 03, 2016
Excellent work. Thank you! - Anonymous
August 18, 2016
this is perfect, thank you so much! - Anonymous
June 05, 2018
WowThank you!!