Script to get all site collections and subsites from entire farm

sns 9,246 Reputation points
2023-03-08T17:44:01.29+00:00

Is there any script to fetch site collections and it’s sub site list from entire farm to csv file

with site name, size, site owner

thank you

Microsoft 365 and Office | SharePoint Server | For business
0 comments No comments
{count} votes

Accepted answer
  1. Emily Du-MSFT 51,846 Reputation points Microsoft External Staff
    2023-03-09T06:05:10.86+00:00

    You could 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://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.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Gupta, Vibhor 0 Reputation points
    2023-09-14T08:32:13.6966667+00:00

    Is this script giving in MB or GB

    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.