6

How to get number of subsites in a site collection using Powershell?

15

or simply:

$site = Get-SPSite http://YourSharePointSite
$site.AllWebs.Count
  • @BennySkogberg: Thanks! At least, it is simple, and that is often the most important when we need the answer quickly. – pholpar Apr 29 '15 at 11:37
5
if ($ver.Version.Major -gt 1) {$host.Runspace.ThreadOptions = "ReuseThread"} 
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
{
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

$sites = Get-SPSite <SiteCollectionUrl>   
$noOfWebs = 0

foreach ($web in $sites.AllWebs)
{
    $noOfWebs++
}

If ($sites -ne $null)
{
    $sites.Dispose();
}

If ($web -ne $null)
{
    $web.Dispose();
}

Write-Host "Total No of Subsites: " $noOfWebs
4

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.