SharePoint: Get All Sites and Webs from SharePoint farm using PowerShell
Introduction
This will explain frequent used SharePoint PowerShell commands.
Applies To
The examples demonstrated below are tested with and apply to the following versions of SharePoint:
- SharePoint 2013
- SharePoint 2016
- SharePoint 2019
Get All Site Collections from SharePoint farm(Including Central Admin Web App)
The below command will get all Sites collection URLs into a Sites.txt file from all web applications in SharePoint farm including a central admin web application.
Get-SPWebApplication -IncludeCentralAdministration | Get-SPSite -Limit All | Select URL | Ft -autosize -wrap | Out-File -FilePath "Sites.txt"
Get All Site Collections from SharePoint farm (Except Central Admin)
The below command will get all Sites collection URLs into a Sites.txt file from all web applications in SharePoint farm except central admin web application.
Get-SPWebApplication| Get-SPSite -Limit All | Select URL | Ft -autosize -wrap | Out-File -FilePath "Sites.txt"
Get All Site Collections and Webs from SharePoint farm (Including Central Admin Web App)
The below command will get all Sites collection URLs and sub site URLs into a Sites.txt file from all web applications in SharePoint farm including a central admin web application.
Get-SPWebApplication -IncludeCentralAdministration | Get-SPSite -Limit All | Get-SPWeb -Limit All | Select URL | Ft -autosize -wrap | Out-File -FilePath "Sites.txt"
Get All Site Collections and Webs from SharePoint farm (Except Central Admin Web App)
The below command will get all Sites collection URLs and subsite URLs into a Sites.txt file from all web applications in SharePoint farm except central admin web application.
Get-SPWebApplication | Get-SPSite -Limit All | Get-SPWeb -Limit All | Select URL | Ft -autosize -wrap | Out-File -FilePath "Sites.txt"
Get All Site Collections from a Web application
The below command will get all Sites collection URLs into a Sites.txt file from a web application.
Get-SPWebApplication http://sharepointurl/ | Get-SPSite -Limit all | Select Url | Ft -autosize -wrap | Out-File -FilePath "Sites.txt"
Get All Site Collections and Webs from a Web Application
The below command will get all Sites collection URLs and subsite URLs into a Sites.txt file from a web application.
Get-SPWebApplication http://sharepointurl/ | Get-SPSite -Limit All | Get-SPWeb -Limit All | Select Url | Ft -autosize -wrap | Out-File -FilePath "Sites.txt"
Get All site collections and webs in a Web Application (With Filter)
The below command will get all Sites collection URLs and subsite URLs into a Sites.txt file from a web application, but url not contains "://apps-"
Get-SPWebApplication http://sharepointurl/ | Get-SPSite -Limit ALL | Get-SPWeb -Limit ALL | ? {$_.Url -notlike "*://apps-*"} | Select Url | Ft -autosize -wrap | Out-File -FilePath "Sites.txt"