Updated 1 month ago

Export a List of all Document Library in SPO Using PowerShell

by Sruthy

5 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. Similarly, you can retrieve all SPO sites along with their list items for more efficient management.

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. While tracking document library details like size and file count, it might also be useful to have insights on overall storage consumption by files/folders across your SharePoint sites, especially when managing large volumes of data. Also, you must check the files & folders created by external users, to find if any suspicious 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.

Effective SharePoint Online Reporting with AdminDroid

The document library report script retrieves valuable details about the SharePoint Online document libraries. For efficient management and storage optimization, admins need to know more details like hidden libraries, empty libraries, custom permissions, etc. AdminDroid SharePoint Online reporting tool covers everything for you! Get a glimpse of what the tool provides below.

  • All SharePoint document libraries
  • Hidden document libraries
  • Empty libraries
  • Inactive document libraries
  • Document libraries with IRM enabled
  • Document libraries with no Versioning
  • Document libraries with custom permission

SPO document library report - AdminDroid Office 365 Reporter

Moreover, AdminDroid provides over 1800 in-depth reports, 30+ stunning dashboards, and more exciting features that let you manage all your Microsoft 365 services like never before.

Download AdminDroid today and enhance your Microsoft 365 management effectively!

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