Thursday, 14 June 2018

Find and Export all SharePoint Online Sites using Powershell

In this post, I am going to share powershell script to get a list of sites in Office 365. We can easily extract all sites using the SharePoint Online Management shell cmdlet Get-SPOSite.

Before proceed Install the SharePoint Online Management Shell:
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.
#Replace your admin site url
$AdminUrl = "https://contoso-admin.sharepoint.com/"
#Retrieve all site collections
Connect-SPOService -Url $AdminUrl
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.
Get-SPOSite | Select Title, Url, Owner, SharingCapability, LastContentModifiedDate |
Export-CSV "C:\\SharePoint-Online-Sites.csv" -NoTypeInformation -Encoding UTF8

Advertisements
Advertisements

No comments:

Post a Comment