Fetching the list of sub sites from active site collections specfic to particular web application

sns 9,236 Reputation points
2022-11-12T07:33:56.98+00:00

I have got 335 site collections which are active ( exluded locked and read sites) ( these site collections is from particular web application alone)
Now I want to get the list of all sub sites from these 335 site collections, Could you please share me the script for this, thank you.
It is sharepoint 2013

SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,936 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Tong Zhang_MSFT 9,146 Reputation points
    2022-11-14T06:42:18.937+00:00

    Hi @sns ,

    According to my research and testing, please try to use the following PowerShell code to get the list of sub-sites from web application:

    Get-SPWebApplication <WebApp URL> | Get-SPSite -Limit ALL | Get-SPWeb -Limit ALL  
    

    Hope it can help you. Thanks for your understanding.

    ---------------------------------------------------------------------
    Update---------------------------------------------------------------------
    Since you already have a CSV list of active site collections, please try to use the following script to get the list of sub-sites:

    #Requirement: sharepoint online get all subsites powershell  
    #Load SharePoint CSOM Assemblies  
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"  
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"  
       
    #Variables  
    $SiteURL = Import-CSV -path "C:\siteurl.csv" -Header("url")   
          
    $Cred= Get-Credential  
     foreach ($Url in $SiteURL ){  
        #Setup the context  
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($Url.url)  
        $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)  
          
        #Get the web  
        $Web = $Ctx.web  
        $Ctx.Load($Web)  
           
        #get all subsites in sharepoint online powershell  
        $Ctx.Load($Web.Webs)  
        $Ctx.executeQuery()  
       
        #Loop through each subsite and get subsite URL  
        ForEach ($Subweb in $web.Webs)   
        {  
           Write-host $Subweb.url   
        }   
    }  
    

    More information for reference: PowerShell to Get All Subsites in a Site Collection

    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.