Retrieve all site collections under particular content databases using PowerShell and SharePoint 2016 server object model

Retrieve all site collections under particular content databases using PowerShell and SharePoint 2016 server object model
InfoPath alternatives for form designing SharePoint

In this post, we will discuss how we can retrieve all site collections presented under a particular content database using PowerShell and using SharePoint 2016 server object model.

PowerShell:
Here I have a content database name as: WSS_Content_808ab8b0aa0b4298bd1e626628caa80d

Write the below command to get all the site collections presented in the content database:

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue

Get-SPSite -ContentDatabase “WSS_Content_808ab8b0aa0b4298bd1e626628caa80d”

If you want to retrieve in csv or text format then you can write the below:

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue

Get-SPSite -ContentDatabase “WSS_Content_808ab8b0aa0b4298bd1e626628caa80d”> E:\AllSites.txt

Or

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue

Get-SPSite -ContentDatabase “WSS_Content_808ab8b0aa0b4298bd1e626628caa80d”> E:\AllSites.csv

Once you run the above command you can see all site collections like below:

 Retrieve all site collections under particular content databases using PowerShell and SharePoint 2016 server object model
Retrieve all site collections under particular content databases using PowerShell and SharePoint 2016 server object model

SharePoint 2016 Server Object Model:
We can also retrieve all site collections under content databases by using SharePoint 2016 server object model.

string s = string.Empty;
SPSite oSiteCollection = new SPSite(“http://mypc:29024/sites/HydTraining/”);

SPSiteCollection sc = oSiteCollection.ContentDatabase.Sites;

foreach (SPSite site in sc)

{

s += “Site Collection URL: ” + site.Url + “\n”;

}

label10.Text = s.ToString();

Once you run this it will display all the site collections like below:

 Retrieve all site collections under particular content databases using PowerShell and SharePoint 2019 server object model
Retrieve all site collections under particular content databases using PowerShell and SharePoint 2019 server object model

Hope this will be helpful.

Similar SharePoint 2013 Tutorials

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →

Leave a Reply