List all SharePoint site collections and subsites exists in particular web application using powershell script
# creates two texts file(allSites.txt, allWebs.txt) having list of all SPSites and SPWebs
#
# This file is simple txt file, line separated, of the URL's for each object.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Start-SPAssignment -Global
$siteLimit = 500
function GetAllSites([string]$webAppUrl)
{
$allSites = Get-SPWebApplication $webAppUrl `
| Get-SPSite -Limit $siteLimit | `
ForEach-Object { $_.URL }
$allSites
}
function GetAllWebs([string]$webAppUrl)
{
$allWebs = Get-SPWebApplication $webAppUrl `
| Get-SPSite -Limit $siteLimit | `
foreach { $_.AllWebs | foreach {$_.URL } }
$allWebs
}
$rootUrl = "Web Application URL"
"Sites"
$sites = GetAllSites $rootUrl
"Webs"
$webs = GetAllWebs $rootUrl
$sites | Out-File -FilePath "allSites.txt" -Force
$webs | Out-File -FilePath "allWebs.txt" -Force
Stop-SPAssignment -Global
====================================================================
Save above code as .ps1 and run on powershell console and check two text file generated on same location.