Get Site Collections per Content Database oneliner

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

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

Now let’s say you want to save this output to a .txt file, you can add,
> C:sitecollections.txt

The full command would be:

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

Advertisements

Author: "Sharepoint Thoughts"

I’m a Microsoft Certified IT Professional with 5+ Years Experience on SharePoint Technologies. Worked extensively on “SharePoint 2007”, “SharePoint 2010”, “SharePoint 2013” & “SharePoint 2016” on Implementation, Configuration & Troubleshooting several Projects.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s