Monday, October 10, 2016

Get All Site Collections in a Web Applications using PowerShell

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 "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 | 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 | 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



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!


You might also like:

Related Posts Plugin for WordPress, Blogger...