Export all SharePoint Online Sites using PowerShell

How to extract all sites using the SharePoint Online Management shell cmdlet Get-SPOSite. ?

Before proceed Install the SharePoint Online Management Shell:

a. Download SharePoint Online Management Shell
b. Run the installer
c. Once you have installed the downloaded setup, run the below command to load this module

  • Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking

Note: If powershell console already opened, close and open the powershell again after installing the above setup.

We need admin site url to connect SharePoint Online service, you can refer this post to Get SharePoint Online Admin Site Url. Once you got the admin site url run the below script after replacing your AdminUrl to list all sites.

  1. #Replace your admin site url

  2. $AdminUrl = "https://contoso-admin.sharepoint.com/"

  3. #Retrieve all site collections

  4. Connect-SPOService -Url $AdminUrl

  5. Get-SPOSite | Select Title, Url, Owner

If you want to retrieve all the available properties, run the below command, it will list all the attributes of first site.

  • Get-SPOSite | Select -First 1 | FL

You can also filter the sites based on any available property, the below command lists only sites with sharing capability enabled as ExternalUserSharingOnly.

  • Get-SPOSite | Where-Object {$_.SharingCapability -eq "ExternalUserSharingOnly"}

Run the below command to list sites with share capability disabled.

  • Get-SPOSite | Where-Object {$_.SharingCapability -eq "Disabled"}

Export all SharePoint Online Sites to CSV

Run the below command to export all the required details of spo sites to csv file.

  1. Get-SPOSite | Select Title, Url, Owner, SharingCapability, LastContentModifiedDate |

  2. Export-CSV "C:\SharePoint-Online-Sites.csv" -NoTypeInformation -Encoding UTF8