SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to be able to see the number, names, url of all site collections there are in a given farm. Would there be a powershell command to do that?

share|improve this question
up vote 7 down vote accepted

There should be a powershell equivalent of stsadm.exe -o enumsites -url > "U:\XML\siteowners.xml" which is what I use to generate XML for import into Excel to view all top level site collections, the owners, the content db it lives in and the size/quota information.

share|improve this answer
All the answers were correct but I loved this one because of the xml formatted output! – Regmi Nov 1 '11 at 21:27
While this answer is correct, stsadm has been deprecated; I posted an answer that shows how to output PowerShell objects as XML. – webdes03 Nov 2 '11 at 1:12
Just not on 2010 yet :-( – Eric Alexander Nov 2 '11 at 12:02

If all you want is a list of all site collections in the farm, all you have to do is open a PowerShell window, load the SharePoint snapin if you haven't (Add-PSSnapin Microsoft.SharePoint.PowerShell), and type Get-SPSite.

If you want to return the list of site collections for a specific web application, the easiest way is to just pipe it as Get-SPWebApplication http://intranet | Get-SPSite.

If you want to grab additional information like boflynn suggested, you can also do this with a pipe; no need to script, or loop: Get-SPWebApplication http://intranet | Get-SPSite | Select ID, Url.

You can also easily convert any PowerShell object or object array into XML using the Export-Clixml cmdlet. As an example, here's the previous command to get the ID and Url of all intranet web application sites, piped to an XML file: Get-SPWebApplication http://intranet | Get-SPSite | Select ID, Url | Export-Clixml c:\intranetsites.xml

There's many output and conversion options; likewise, you also have the ability to output as a CSV using Export-Csv.

Previous answers are not incorrect, but these are cleaner and shorter ways to do it.

share|improve this answer
This can also display the URL for Central Administration: Get-SPWebApplication -IncludeCentralAdministration – Underverse Oct 13 '15 at 0:09

Get-SPSite will return the site collections for you. If you want more details, you can loop through them for further processing:

foreach($site in Get-SPSite) {
    echo $site.Url
    echo $site.ID
    #anything else here
share|improve this answer
I find this was one to be the second best answer as I could add site properties as I wanted. – Regmi Nov 1 '11 at 21:29
Excellent. For a list of values for which can be displayed: Get-SPSite | Get-Member * Output formatted on one line: foreach($site in Get-SPSite -Limit ALL) { Write-Host ($site.Url + " - " + $site.ID) } – Underverse Oct 13 '15 at 0:29
$siteUrl = Read-Host "Enter Site URL"
$rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$spWebApp = $rootSite.WebApplication

foreach($site in $spWebApp.Sites)
    foreach($siteAdmin in $site.RootWeb.SiteAdministrators)
        Write-Host "$($siteAdmin.ParentWeb.Url) - $($siteAdmin.DisplayName)"
share|improve this answer

If you copy your question title and past it into google search, the first link search result will contain a powershell script that describes how to collect site collections. But do not fogive to add Add-PSSnapin Microsoft.SharePoint.PowerShell command befor your comands.

share|improve this answer
Not true, the first link ends up pointing to this very page! – Alan M Mar 8 '13 at 18:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.