Is possible to get a count of items from all folders and subfolders from a specific parent folder in a sharepoint online document library?

Anonymous
2023-06-13T14:19:47.3433333+00:00

Is possible to get a count of items from all folders and subfolders from a specific parent folder in a sharepoint online document library? I have tried various script found in various webs, but they either count a whole document library or only the first level under the parent folder, I've not had alot of experience with powershell so I wasn't able to fine tune what I was using to get the counts I needed.

I appreciate any help I can get.

Thank you,

DWTKBrook

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2023-06-14T03:11:11.27+00:00

    Hi @DWTKBrook

    I will recommend you to use pnp powershell method Get-PnPFolderItem to get all items under a specific parent folder including folders and subfolders. Please refer to the following script

    #Set Variables
    $siteURL = "https://xxx.sharepoint.com/sites/xiexin"
    $FolderURL = "/LibraryName/parentfolder" #Document Library Site Relative URL
    $UserName="******@xxxx.onmicrosoft.com"
    $Password = "******"
     
    $SecurePassword = ConvertTo-SecureString -String $Password -AsPlainText -Force
    $Cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $UserName, $SecurePassword
     
    #connect to sharepoint online site using powershell
    Connect-PnPOnline -Url $siteURL -Credentials $Cred
    
    $items=Get-PnPFolderItem -FolderSiteRelativeUrl $FolderURL -Recursive
    write-host -ForegroundColor Green $items.count
    

    Here is the document for Get-PnPFolderItem, please make a reference.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.