The script gets you the below details about the SharePoint content database,
- Content database located server
- CDB status
- CDB size
- Site Level warning
- Maximum allowed sites
- Total site collection
- Site collection URL
- Subsite count
- Site collection size
- $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
- $LogFile = ".\ContentDatabaseReportPatch-$LogTime.rtf"
-
- # Add SharePoint PowerShell Snapin
-
-
- if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
- Add-PSSnapin Microsoft.SharePoint.Powershell
- }
-
- $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
- Set-Location $scriptBase
-
-
- #Deleting any .rtf files in the scriptbase location
- $FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf
- if($FindRTFFile)
- {
- foreach($file in $FindRTFFile)
- {
- remove-item $file
- }
- }
-
-
- start-transcript $logfile
-
- Function ContentDatabaseReport()
- {
-
- $CDBName = read-host "Enter the content database name "
- write-host "Generating report for the Content database " $CDBName -fore yellow
- write-host "Processing report..................." -fore magenta
- $Output = $scriptBase + "\" + "03ContentDBDetails.csv";
- "CDBName" + "," + "CDBServer" + "," + "CDBStatus" + "," + "CDBSize(MB)" + "," + "SiteLevelWarning" + "," + "MaximumAllowedSites" + "," + "TotalSiteCollection" + "," + "SiteCollectionURL" + "," + "Web(s)Count" + "," + "SiteCollectionSize(MB)" | Out-File -Encoding Default -FilePath $Output;
- $CDB = get-spcontentdatabase -identity $CDBName
- $CDB.name + "," + $CDB.server + "," + $CDB.Status + "," + $CDB.DiskSizeRequired/1048576 + "," + $CDB.WarningSiteCount + "," + $CDB.MaximumSiteCount + "," + $CDB.Currentsitecount + "," + $empty + "," + $empty + "," + $empty | Out-File -Encoding Default -Append -FilePath $Output;
- $sites = get-spsite -limit all -ContentDatabase $CDBName
- foreach($site in $sites)
- {
- $empty + "," + $empty + "," + $empty + "," + $empty + "," + $empty + "," + $empty + "," + $empty + "," + $site.url + "," + $site.allwebs.count + "," + $site.usage.storage/1048576 | Out-File -Encoding Default -Append -FilePath $Output;
- }
- write-host "Report collected for content database " $CDBName " and you can find it in the location " $output -fore green
-
- }
-
- ContentDatabaseReport
-
- write-host ""
- write-host "SCRIPT COMPLETED" -fore green
-
- stop-transcript