Find the Total Number of Documents In one SharePoint Online Folder using Power Shell
Nabeel Mukhtar
Cloud Migration Expert | Office 365 ? Google Workspace | Exchange & SharePoint Migration | Data Migration Engineer | BitTitan Product Expert | Technical Consultant | Pre-Sales Technical Consultant at BitTitan
When it comes to managing a SharePoint Online environment, it's crucial to keep track of the number of documents stored in each document library. While it's easy to manually count the number of documents in a single library, this can become a time-consuming task if you're dealing with multiple libraries. Luckily, PowerShell commands can help you quickly and efficiently find out how many documents live in a single document library. In this article, we will guide you through the steps required to use PowerShell to count the number of documents in a single document library in your SharePoint Online environment. By the end of this article, you'll have a better understanding of how PowerShell can help you manage your SharePoint Online document libraries more efficiently.
1. Connect to SharePoint Online using PowerShell
Step 1: Install the SharePoint Online Management Shell or SharePoint Online PowerShell Module.
Step 2: Connect to SharePoint Online PowerShell using the Connect-SPOService cmdlet
Connect-SPOService -Url https://abc-admin.sharepoint.com `-credential [email protected]
Step 3: Start using SharePoint Online PowerShell cmdlets!
2. Please run the below PowerShell script as an admin to get counts of files:
??
#Config Variables??
$SiteURL = "https://domain.sharepoint.com/sites/sitename"??
$ListName ="libraryname"??
#Any file under the given path??
$FolderServerRelativePath = "/sites/sitename/libraryname/foldername*" #Any file under the given path??
???
#Connect to PnP Online??
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)??
???
#Get all files from folder??
$Files = Get-PnPListItem -List $ListName | Where {$_.FieldValues.FileRef -like $FolderServerRelativePath -and $_.FileSystemObjectType -eq "File" }??
Write-Host "File Counts:" $Files.Count
Technology professional
1 年Also curious if you can use bittitan to migrate directories within a library instead of the whole library.
Technology professional
1 年Do you have a method for libraries with more than 5000 items?