Get the list all sites and subsites in SharePoint online using Powershell

SR VSP 1,251 Reputation points
2023-10-02T17:49:01.84+00:00

Guys,

I'm looking for a script to get the list of all sites and subsites in SharePoint online using PowerShell and export the file in to CSV any advise here ?

Tried with PNP but unable authorize my admin account so any other methods would be helpful.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,817 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,041 questions
{count} votes

2 answers

Sort by: Most helpful
  1. ChengFeng - MSFT 5,030 Reputation points Microsoft Vendor
    2023-10-03T02:50:00.44+00:00

    Hi @SR VSP

    During my investigation, I found a post with the same needs as yours. The following code is for your reference:

    Please run following PowerShell as administrator.

    Add-PSSnapin Microsoft.SharePoint.PowerShell -EA 0
     
    Start-SPAssignment –Global
    $spSites = Get-SPSite -Limit All
    $spWAs = Get-SPWebApplication -IncludeCentralAdministration
    $csvs = @()
    
    #Get Web Application Data
    Write-Host("Getting Web Application Data")
    $spWAs | select Name, DisplayName, Id, Url, ApplicationPool, @{Expression={$_.ApplicationPool.Name}}, @{Expression={$_.ApplicationPool.UserName}}, DefaultQuotaTemplate | Export-CSV $bkdir\SPWebApplication.csv
    $csvs += C:\SPWebApplication.csv
    
    #Get Site Collection Data
    Write-Host("Getting Site Collection Data")
    $spSites | select Id, HostName, Url, Owner,WebApplication, ContentDatabase, RootWeb, LastContentModifiedDate, @{Expression={$_.Usage.Storage}} | Export-CSV $bkdir\SPSite.csv
    $csvs += C:\SPSite.csv
     
    #Get Site Data
    Write-Host("Getting Site Data")
    $spSites | Get-SPWeb -Limit All | select ID, Title, Author, Url, WebTemplate, LastItemModifiedDate, IsRootWeb | Export-CSV $bkdir\SPWeb.csv
    $csvs += C:\SPWeb.csv
    Stop-SPAssignment –Global
    

    Reference:

    https://learn.microsoft.com/en-us/answers/questions/1187774/script-to-get-all-site-collections-and-subsites-fr

    https://gist.github.com/ciphertxt/52287bc26b8bc95a89d0


    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.

    Best Regards

    Cheng Feng


  2. Alvaro Avila 80 Reputation points
    2024-07-25T13:48:34.03+00:00

    You can use this app: https://github.com/Barbarur/NovaPoint

    Free, open-source and easy to use. You can get a report of all your sites and subsites easily and many other reports from your SharePoint Online.

    0 comments No comments

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.