As an Administrator, there might be a need to view all the site collections under a web-application in SharePoint. We can get a list of site collections in a particular web application using the Powershell cmdlet Get-SPSite.
Before proceed, run the following command to add SharePoint PowerShell management snapin.
Add-PSSnapin Microsoft.SharePoint.PowerShell
The following PowerShell script find and list all site collections details in a given web application. You have to change the $url value with your own webapplication url.
$url ='http://sharepoint_server:90/' $Site= Get-SPSite $url $spWebApp = $Site.WebApplication #Enumerate all site collections from webapplication $spWebApp.Sites | Select-Object @{n="Name"; e={$_.RootWeb.Title}},Url,ContentDatabase | FL
You can also export the site collection details to csv file by using the powershell cmdlet Export-CSV.
$url ='http://sharepoint_server:90/' $Site= Get-SPSite $url $spWebApp = $Site.WebApplication #Enumerate site collections list from webapplication $spWebApp.Sites | ForEach-Object { New-Object -TypeName PSObject -Property @{ Name = $_.RootWeb.Title Url = $_.Url WebApplication= $web.Name Database = $_.ContentDatabase }} | Export-CSV "C:\SiteCollections.csv" -NoTypeInformation -Encoding UTF8
Advertisement