1

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 – Heiko Hatzfeld_MSFT Sep 24 '18 at 13:08
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, privacy policy and cookie policy

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