How to get All Site Collections on each SharePoint Content Database using Powershell

This short post can help you get all the report you need for your IT Managers. Have you ever been asked how many databases you have for your SharePoint Farm? That is easy go get. Just open SharePoint 2010/2013 Management Shell and type Get-SPDatabase. This will list all the databases configured for your SharePoint farm. The powershell needs to run on any of the SharePoint Servers with farm admin account or any user with farm admin priviledge. The purpose of this post is not this.

This short post explains how to get all content databases, and for each of the content databases, it will show you the site collections within this content database, as it contains only 1 line of PowerShell code, and is not very hard to understand.

Here is your one line of Script

Get-SPContentDatabase | %{Write-Output “- $($_.Name)”; foreach($site in $_.sites){write-Output $site.url}}

And the following is the screenshot of the output of the script from my SharePoint 2013 test farm.

2016-04-27_10-42-51

 

Hope this helps

Enjoy #Powershell

Tesfaye Gari tesfaye.gari@gmail.com OR @tesfayegari

ADDRESS

6066 Leesburg Pike Ste 320
Falls Church, Virginia 22044
Phone: (240) 547-6851

About MTM

MTM Training and Consulting is started by a group of highly qualified and motivated Information Technology Professionals to help you boost your IT career, and your company's productivity