Updated 4 days ago

Export a List of all Document Library in SPO Using PowerShell

by Sruthy

4 min read

No Comments

The document library in SharePoint Online is used to store all the files and folders related to the site. However, storing more files and folders or larger files could lead to greater storage consumption. So, it is essential to periodically track the library size, count of files & folders, etc., to prevent storage exceeding errors and ensure smooth operations.

Monitor SharePoint Online Document Library in Microsoft 365

Verifying document library details like size, count of files and folders, creation date, version history, and more can’t be achieved using the Microsoft 365 admin center or SharePoint admin center. You can view a few of the details by manually visiting individual sites and customizing columns for each document library. So, admins need to go with SharePoint PnP PowerShell. They can retrieve the document library details using the ‘Get-PnPList’ cmdlet. However, getting the customized data using this cmdlet is challenging and consumes more time.

Don’t fret! We have developed a PowerShell script to instantly export all document library details in SharePoint Online.

Script Highlights

  1. The script automatically verifies and installs the PnP module (if not installed already) upon your confirmation.
  2. Retrieves all the document libraries in SharePoint Online along with their details.
  3. Provides a list of all document libraries in a single site.
  4. Allows to get all document libraries and their details for multiple sites.
  5. The script can be executed with an MFA-enabled account too.
  6. The script supports Certificate-based authentication (CBA) too.
  7. Exports the report results to a CSV file.
  8. The script is scheduler friendly.

Download Script: DocumentLibraryReport.ps1

Sample Output

The script analyses and exports all the SharePoint Online document library with the following attributes:

  • Site Name
  • Site URL
  • Document Library Name
  • Document Library URL
  • Library Size
  • Library Size (bytes)
  • Files Count
  • Folders Count
  • Created On

SharePoint document library report - Sample output

Export SharePoint Document Library Report Using PowerShell – Script Execution Methods

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

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

The above example lets you export all document library in SPO into a CSV file.

Note: When running the script, you will need to authorize each site available in the organization. So, we recommend using method 3 (Certificate-based authentication) when running the script to avoid sign-in prompts for each site. You can also pass credentials to avoid sign-in prompts if required.

Method 2: You can explicitly pass credentials (username and password) and execute the script.

You can use this method to schedule the script using task scheduler for non-MFA admin accounts.

Method 3: You can also use certificate-based authentication to run the script. This method is also scheduler friendly. To do this, you must register the app in Azure AD and connect to SPO with certificate-based authentication.

You can use either a certificate issued by a recognized certificate authority (CA) or create a self-signed SSL certificate.

Download all Document Library Details in SPO Using PowerShell

Make use of the PowerShell script and find customized reports based on your specific needs. Explore the use cases below.

  1. List all document libraries in SharePoint Online
  2. Get a list of document libraries for a single site in SharePoint Online
  3. Get all document libraries for multiple sites

1. List all Document Libraries in SharePoint Online

Verifying all the document libraries available on all sites in SharePoint Online is essential to identify and prevent storage exceeding errors.

To get the SharePoint document library report for all sites in SharePoint Online, use the below cmdlet.

Admins can get the file/folder count, library size, document library name, site name, and more. Also, you must check the files & folders created by external users, to find if any suspicious or large files are uploaded by them.

2. Get a List of Document Libraries for a Single Site in SharePoint Online

If admins want to review a specific site related to any ongoing project, they can get all the document library details to reduce storage consumption by deleting unwanted files or folders.

To find a list of document libraries for a specific SharePoint site, run the below cmdlet with the ‘-SiteAddress’ parameter.

Here, admins will get a list of all the document libraries and their details in a specified site in SharePoint Online.

3. Get all Document Libraries for Multiple Sites in SharePoint Online

In SharePoint Online, communication sites and other team sites are available, which might not be considered important and don’t require monitoring. In such scenarios, admins can focus only on crucial sites, eliminating other sites by including the desired site URLs in a CSV file. Then, run the script by specifying the path of the created CSV file in the ‘-SitesCsv’ parameter.

Remember that you should provide the list of required site URLs with a column name ‘SitesUrl’.

Sample Input:

SPO document library report - bulk sites input

Note: Admins can create SPO alerts on documents to instantly notified about any crucial changes or happenings in the organization.

Points to Remember:

  1. Note that the script will verify and retrieve document library details for the sites where you are a member. Otherwise, you will get ‘Access is denied’ or ‘unauthorized operation’ errors during script execution.
  2. To avoid ‘Access is denied’ errors, use the Certificate-based authentication (CBA) method to get details for the sites even if you are not a member of the site.
  3. Check that you have the PowerShell 7 version to run the script.

I hope this blog helps you to instantly verify all the document libraries in SharePoint Online and their details effectively. For more queries, reach us through the comment section. Happy scripting!

Share article