Friday, April 10, 2015

list all site collections in all databases of database server using Powershell

Someone asked me how to retrieve list of all site collection residing in all content database of a database server. So have prepared a small script for this...

To Get the list of server execute below command


Above command will list all server in the farm.

Copy the SQL/Database server you intend to query...

$DBServerInstance = "XXXXXXXX"

Replace xxxx with the database server name/Alias if you are using alias.

$dbserver = Get-SPDatabase –ServerInstance $DBServerInstance

foreach ($db in $dbserver)
                Get-SPSite –ContentDatabase $db – Limit all | Select URL


You can redirect the output of foreach loop contents to a text file.