Get All Site Collections in a Web Applications using PowerShell

How to get all site collections of a web application in SharePoint?

To get all site collections in web application, from SharePoint central Admin, follow these steps:

  • Go to SharePoint Central Admin Site >> Application Management 
  • Click on the “View all site collections” link under Site Collections Group. Select your web application. This page lists all site collections in the selected web application.
    sharepoint get all site collections in web application

Get all site collections in web application using PowerShell:

Here is the PowerShell to list all site collections in web application.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set the Web application URL
$WebAppURL="http://intranet.crescent.com"

#Get the Web Application        
$WebApp = Get-SPWebApplication $WebAppURL

#Get all Site collections from the web application
$SitesCollection  = $WebApp.Sites

#Enumerate all site collections in the web application
Foreach($Site in $SitesCollection)
{
    #Get Site Collection URL, Owner, Content Database Details
    Write-host $Site.URL
}

While the above code written in classic manner, you can use PowerShell one-liner to get list of all site collections in web application:

Get-SPWebApplication "http://intranet.crescent.com" | Get-SPSite | Select URL

PowerShell to get all site collections in a web application:

This time, lets use PowerShell expressions to dig into site collection properties, say: Site Name, content database, etc.

Get-SPWebApplication "http://intranet.crescent.com" | Get-SPSite -Limit All | Select URL,@{Name="Site Name"; Expression={$_.RootWeb.Title}},Owner 

How to get all site collections in a web application and Export to CSV?

How about get all site collections in a web application using PowerShell and Export to CSV?

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Web application URL and CSV File location Variables
$WebAppURL="http://intranet.crescent.com"
$CSVFile="C:\SitesList.csv"

#Get list of site collections in a web application powershell
Get-SPWebApplication $WebAppURL | Get-SPSite -Limit All | ForEach-Object {
    New-Object -TypeName PSObject -Property @{
             SiteName = $_.RootWeb.Title
             Url = $_.Url
             DatabaseName = $_.ContentDatabase.Name }
} | Export-CSV $CSVFile -NoTypeInformation

This Script gets all site collections from the given web application and exports the site collection data to CSV
how to get all site collections in a web application using powershell

Salaudeen Rajack

Information Technology Professional with Two decades of SharePoint Experience.

6 thoughts on “Get All Site Collections in a Web Applications using PowerShell

Leave a Reply