Find the Total Number of Documents In one SharePoint Online Folder using Power Shell
Credit: Microsoft Learn

Find the Total Number of Documents In one SharePoint Online Folder using Power Shell

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


No alt text provided for this image
No alt text provided for this image
John Troup

Technology professional

1 年

Also curious if you can use bittitan to migrate directories within a library instead of the whole library.

回复
John Troup

Technology professional

1 年

Do you have a method for libraries with more than 5000 items?

要查看或添加评论,请登录

Nabeel Mukhtar的更多文章

社区洞察

其他会员也浏览了