Get All SharePoint Online Site Collections Inventory using PowerShell

Requirement: Get all site collections inventory in SharePoint Online using PowerShell.

PowerShell to Get All SharePoint Online Site Collections Inventory

Have you ever wanted to prepare an inventory of SharePoint Online sites in your tenant? Keeping track of all the sites in a SharePoint Online environment can be important for governance and security reasons. A site inventory is a list of all the sites in a SharePoint Online environment, along with important information such as Site Title, URL, Template, Sharing settings, etc. In this post, we will take a look at how to use PowerShell to inventory all of the sites in your SharePoint Online tenancy. This will help you keep track of which sites are being used in your organization and what content is stored on them. Let’s get started!

Let’s get a list of SharePoint Online sites using PowerShell:

Import-Module Microsoft.Online.SharePoint.Powershell -DisableNameChecking

#Config Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$ReportOutput="C:\Temp\SPOStorage.csv"

#Get Credentials to connect to SharePoint Admin Center
$Cred = Get-Credential

#Connect to SharePoint Online Admin Center
Connect-SPOService -Url $AdminSiteURL -Credential $Cred

#Get All site collections
$SiteCollections = Get-SPOSite -Limit All
Write-Host "Total Number of Site collections Found:"$SiteCollections.count -f Yellow

#Array to store Result
$ResultSet = @()

#Loop through each site collection and retrieve details
Foreach ($Site in $SiteCollections)
{
    Write-Host "Processing Site Collection :"$Site.URL -f Yellow

    #Get site collection details    
    $Result = new-object PSObject
    $Result | add-member -membertype NoteProperty -name "Title" -Value $Site.Title
    $Result | add-member -membertype NoteProperty -name "Url" -Value $Site.Url
    $Result | add-member -membertype NoteProperty -name "LastContentModifiedDate" -Value $Site.LastContentModifiedDate
    $Result | add-member -membertype NoteProperty -name "Status" -Value $Site.Status
    $Result | add-member -membertype NoteProperty -name "LocaleId" -Value $Site.LocaleId
    $Result | add-member -membertype NoteProperty -name "LockState" -Value $Site.LockState
    $Result | add-member -membertype NoteProperty -name "StorageQuota" -Value $Site.StorageQuota
    $Result | add-member -membertype NoteProperty -name "StorageQuotaWarningLevel" -Value $Site.StorageQuotaWarningLevel
    $Result | add-member -membertype NoteProperty -name "Used" -Value $Site.StorageUsageCurrent
    $Result | add-member -membertype NoteProperty -name "CompatibilityLevel" -Value $Site.CompatibilityLevel
    $Result | add-member -membertype NoteProperty -name "Template" -Value $Site.Template
    $Result | add-member -membertype NoteProperty -name "SharingCapability" -Value $Site.SharingCapability
    
    $ResultSet += $Result
}  
 
#Export Result to csv file
$ResultSet |  Export-Csv $ReportOutput -notypeinformation
 
Write-Host "Site Quota Report Generated Successfully!" -f Green   

This will generate a report containing a list of all the sites in the tenant and the important site information. You can open the output CSV file in a spreadsheet program like Microsoft Excel to verify the report. Here is the report generated:

sharepoint online get all site collections powershell

Here is the list of all properties you can retrieve from a SharePoint Online site collection:

  • LastContentModifiedDate
  • Status
  • ResourceUsageCurrent
  • ResourceUsageAverage
  • StorageUsageCurrent
  • LockIssue
  • WebsCount
  • CompatibilityLevel
  • DisableSharingForNonOwnersStatus
  • Url
  • LocaleId
  • LockState
  • Owner
  • StorageQuota
  • StorageQuotaWarningLevel
  • ResourceQuota
  • ResourceQuotaWarningLevel
  • Template
  • Title
  • AllowSelfServiceUpgrade
  • DenyAddAndCustomizePages
  • PWAEnabled
  • SharingCapability
  • SandboxedCodeActivationCapability
  • DisableCompanyWideSharingLinks
  • DisableAppViews
  • DisableFlows
  • StorageQuotaType
  • SharingDomainRestrictionMode
  • SharingAllowedDomainList
  • SharingBlockedDomainList

Use this PowerShell script in SharePoint Online Management Shell to get all available properties of a SharePoint Online site collection:

#Config Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$ReportOutput="C:\Temp\SPOStorage.csv"

#Get Credentials to connect to SharePoint Admin Center
$Cred = Get-Credential

#Connect to SharePoint Online Admin Center
Connect-SPOService -Url $AdminSiteURL -Credential $Cred

#Get all Site collections details and Export to CSV
Get-SPOSite -Limit ALL -Detailed | Export-Csv -Path $ReportOutput -NoTypeInformation

PnP PowerShell to Get Site Collection Details in SharePoint Online

Here is the PowerShell to get SharePoint Online site detailed info:

#Config Variables
$SiteURL = "https://Crescent.sharepoint.com/sites/Marketing"

#Connect to PnP Online
Connect-PnPOnline -Url $AdminCenterURL -Credentials (Get-Credential)

#Get the site collection
$Site = Get-PnPTenantSite -Url $SiteURL -Detailed

#Get Site collection details
Write-host "Title:" $Site.Title
Write-host "Url:" $Site.Url
Write-host "Subsites Count:" $Site.WebsCount
Write-host "Last Content Modified Date:" $Site.LastContentModifiedDate
Write-host "Status:" $Site.Status
Write-host "Lock State:" $Site.LockState
Write-host "Storage Quota:" $Site.StorageMaximumLevel
Write-host "Storage Quota Warning Level:" $Site.StorageWarningLevel
Write-host "Used:" $Site.StorageUsage
Write-host "Compatibility Level:" $Site.CompatibilityLevel
Write-host "Template:" $Site.Template
Write-host "Sharing Capability:" $Site.SharingCapability
Write-host "Site Owner:" $Site.Owner

Another post on getting all site collections using PowerShell in SharePoint Online: Get All Site Collections using PowerShell

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

2 thoughts on “Get All SharePoint Online Site Collections Inventory using PowerShell

Leave a Reply

Your email address will not be published. Required fields are marked *