Tuesday, November 12, 2013

Get All SharePoint Site Collections in Content Databases

During audit/migrations, we had a requirement to generate reports on SharePoint content databases and list of sites collections lives in each content database.

PowerShell script to Get all content databases and Site collection:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get all SharePoint content databases available
$ContentDatabases = Get-SPContentDatabase
#Loop through each content database
 foreach($ContentDb in $ContentDatabases)
  {
   Write-Host "`nContent Database Name:  $($ContentDb.Name) Size:$($ContentDb.DiskSizeRequired/1MB) MB " -ForegroundColor DarkGreen
 #Get all site collections in the content database
 Write-Host "Site Collections List:" -ForegroundColor Blue
 foreach($site in $ContentDb.Sites)
 {
  write-host $site.url
 }
  } 
This PowerShell script outputs all SharePoint content databases with their size, and for each of the content database, it gives the list of site collections within the content database.

Get all site collections in a specific content DB:
Lets change the script slightly to get all site collections lives in a particular content database:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
 #Set the Content Database Name
 $ContentDbName = "SP2010_SharePoint_ContentDB"
 #Get the Content Database
 $ContentDb = Get-SPContentDatabase -Identity $ContentDbName
  #Iterate through each site collection in the Content database
  foreach($site in $ContentDb.Sites)
 {
  write-host $site.url
 }
How to Find in Which Content Database a particular Site collection Lives?
Simple! Just use: Get-SPContentDatabase -site http://Site-Collection-URL



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...