How to get number of subsites in a site collection using Powershell?
['https://sharepoint.stackexchange.com/questions/140021', 'https://sharepoint.stackexchange.com', 'https://sharepoint.stackexchange.com/users/41443/']
or simply:

```
$site = Get-SPSite http://YourSharePointSite
$site.AllWebs.Count

```
Using the following code, within the SharePoint Management Shell, you can get the count of Web Applications in the Farm, Site Collections in Web Application, Sites in Site Collection.

```
Write-Host "Web Applications in Farm"
$WebApplications = Get-SPWebApplication
$WebApplications | Measure-Object | Format-List Count

ForEach($WebApplication in $WebApplications) {
    Write-Host "Site Collections in the Web Application named " $WebApplication.Name
    $WebApplication.Sites | Measure-Object | Format-List Count

    ForEach($SiteCollection in $WebApplication.Sites) {
        Write-Host "Webs (Sub-Sites) in the Site Collection with the URL " $SiteCollection.Url
        Write-Host "`nCount : " $SiteCollection.AllWebs.Count "`n`n`n"    
    }    
}

```