I have a site collection "IM". In this site collection I have many subsites and in every subsite I have other subsites.

How can I get all subsites of the site collection using Powrshell?

I started to get first level of subsites but not the second one:

$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null) { Add-PSSnapin Microsoft.SharePoint.Powershell }
$IM = Get-SPWeb "http://manco-intranet/sites/investmentmanager/" 

foreach($Site in $IM)
    foreach($SubIM in $Site.Webs)
        Write-Host $SubIM.title 
  • Not the 100% correct answer... But have you checked "AllWebs" on the Sitecollection level? That way you get all of them with no need for recursion Sep 24, 2018 at 13:08

1 Answer 1


Try with this

Add-pssnapin "Microsoft.Sharepoint.Powershell" 

Get-SPSite "http://SiteCollectionURL" | Get-SPWeb -Limit All | Select Title, URL | 
Export-CSV C:\SharePoint_Sites_Report.csv -NoTypeInformation

Change SiteCollectionURL and path to csv (C:\SharePoint_Sites_Report.csv)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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