Updated 2 weeks ago

Get All Subsites in SharePoint Online Using PowerShell

by AIMA

5 min read

No Comments

In SharePoint Online, subsites are smaller divisions of a main site, each potentially serving different purposes within an organization. Managing these subsites effectively is crucial as they can significantly impact how information and resources are organized and accessed. Well-organized subsites ensure that SharePoint permissions and security settings are correctly applied, allowing users to access the necessary resources based on their roles.

Navigating through multiple subsites in SharePoint Online can be a bit like exploring a maze. Administrators often face the challenge of efficiently managing and auditing these subsites. In this blog, we’ll show you various methods to list all subsites in SharePoint Online, streamlining your management tasks and saving you time.

How to List All Sites & Subsites in SharePoint Online?

Listing all sites and subsites in SPO will help you keep track of your site structure and ensure proper organization. The following are the ways to get the list of all subsites in a site collection in SharePoint Online.

View subsites in the SharePoint admin center: Login to the SharePoint admin center —> Active sites —> Select respective sites —> Settings–> Site content. On this page, selecting the Subsites tab will display all immediate subsites of the site. However, be aware that only first-level subsites are shown. Any second-level subsites will not be listed on this page.

Get subsites using PowerShell: You can use the ‘Get-SPOWeb’ cmdlet to find all subsites associated with a particular site collection. However, to view all subsites across all site collections, you’ll need to pass each site URL individually into the Get-SPOWeb cmdlet.

We’ve developed a handy PowerShell script that helps Microsoft 365 admins easily pull a list of all subsites in SharePoint Online.

Download Script: GetSharePointSubsites.ps1


Script Highlights

  1. Exports subsites of all sites in the SharePoint tenant.
  2. Exports subsites for a list of sites alone.
  3. Retrieves subsites for a specific site based on user input.
  4. Shows the current recycle bin status (Enabled/Disabled) for each site.
  5. Automatically installs the PnP PowerShell module (if not installed already) upon your confirmation.
  6. The script can be executed with an MFA enabled account too.
  7. Exports report results as a CSV file.
  8. The script is scheduler friendly.
  9. The script uses modern authentication to connect SharePoint Online.
  10. It can be executed with certificate-based authentication (CBA) too.

SharePoint Online Subsites Report – Sample Output

The script exports all subsites in SharePoint Online with the following attributes.

  • Site Collection Name
  • Site Collection URL
  • Site Name
  • Site URL
  • Site Description
  • Creation Date
  • Last Modified Date
  • Recycle Bin Enabled

The exported report on all subsites in SharePoint Online looks like the screenshot below.

Get All Subsites in SharePoint Online

Retrieving All Subsites in SPO – Script Execution Steps

  1. Download the script.
  2. Start the Windows PowerShell.
  3. Select any of the methods provided to execute the script.

The script requires a minimum Windows PowerShell version of 7.2 to execute without any error.

Method 1: You can run the script with MFA and non-MFA accounts.

This example extracts all subsites in all site collections in SharePoint Online into a CSV file.

Important: While running the script, you’ll need to authorize for each site regardless of whether MFA is enabled. For example, if you have 7 sites with subsites, you will need to authorize access for each of the 7 sites individually. Additionally, if you’re not an owner of certain sites, you might encounter an unauthorized error and won’t be able to retrieve subsites data. To avoid these issues, use the second method, which lets you gather data from all sites without any authorization checks or errors.

Method 2: You also have the option to run the script using certificate-based authentication, which is scheduler-friendly. When you want to run the script unattended, you can choose this method. To use certificates, you must register the app in Microsoft Entra.

Note – Depending on your requirements, you can create a self-signed certificate.

Get the Most Out of the Script:

The script comes with pre-set filtering options tailored to your exact requirements. Here are a few scenarios where it excels:

  1. List all subsites in a SharePoint Online site collection
  2. Get subsites of specific site collections (Input CSV)

1. List All Subsites in a SharePoint Online Site Collection

By default, the script generates a report for all subsites across all site collections. If needed, you can specify a site address using the SiteAddress parameter to focus solely on subsites within a particular site collection. Simply enter the URL of the specific site you wish to retrieve subsites from.

The above script generates a list of all subsites within a specific site collection named ‘Test.

2. Get Subsites of Specific Site Collections (Input CSV)

Generating reports for a list of site collections enables a more targeted analysis of their subsites. To do this, you can input the site collection details via a CSV file and generate a report for the associated subsites.

Use the SitesCsv parameter to pass the CSV file and retrieve reports for subsites within the specified site collections. For example:

The file must follow the format below: Site names separated by a new line with SitesUrl as header. Not including this header will result in errors when running the script.

Sitenames

The resulting report will display a list of all subsites within the specified sites in SharePoint Online.

Simplify SharePoint Online Management with AdminDroid!

Monitoring SharePoint site activities is crucial for organizational compliance and security. While PowerShell scripts offer direct control, they can be time-consuming and complex, limiting detailed insights. AdminDroid steps in as a comprehensive solution, offering crystal-clear insights with its extensive suite of SharePoint Online reports:

SharePoint Online Site Reports

  • All SharePoint sites
  • Recently created sites
  • Sites over warning quota

File Auditing Activities

  • Files uploaded or downloaded from SharePoint sites
  • Malware-detected files
  • Files shared with anonymous access

Site Membership

  • SPO site admins
  • SPO site owners
  • Site access guest users
  • SPO group membership

External User Activities

  • Files shared to external users
  • Site invitations shared to external users
  • External members added /removed from SPO groups and more.

All Site Collections _ AdminDroid Office 365 Reporter

Looking for an all-in-one solution to streamline your Office 365 management? AdminDroid is the answer! With 1800+ reports and 30+ insightful dashboards, this user-friendly interface covers Exchange Online, SharePoint Online, Microsoft Teams, and OneDrive for Business, etc.

With a 15-day free trial, there’s no reason not to experience the AdminDroid difference! Download AdminDroid today and start optimizing your Microsoft 365 environment!

AdminDroid’s SharePoint Online auditing tool offers comprehensive insights that allow you to monitor suspicious activities regularly and take necessary actions.

In addition, the SharePoint Online dashboard from AdminDroid provides a quick and engaging overview of your SPO environment. This comprehensive approach enhances your SharePoint Online management and ensures robust site security, making AdminDroid’s Microsoft 365 reporter indispensable for efficient administration.

We hope that this blog has helped you with the necessary information to get all SharePoint Online subsites using PowerShell. In addition, to enhance your SharePoint Online security further, you can utilize this set of 9 essential SPO PowerShell scripts. Thanks for reading. If you have any further queries, feel free to reach out to us through the comment section.

Share article