Is there any PowerShell or other way to get a list of full paths for all files and folders in a SharePoint Online Document Library?

frob 4,261 Reputation points
2022-08-10T01:32:03.827+00:00

Hi there

Is there any PowerShell or other way to get a list of full paths for all files and folders in a SharePoint Online Document Library? (Iterating through all folders and subfolders,
etc.).

I have several thousand items, so need an automatic way.

Thanks.

Microsoft 365 and Office SharePoint For business Windows
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 39,916 Reputation points
    2022-08-10T13:46:30.62+00:00

    Hi there,

    This will print out all folder names of a document library:

    Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
    $web = Get-SPWeb 'http://urltoyourwebsite'
    $list = $web.Lists['DocumentLibrary']

    function ListFolders($folder) {
    Write-Host $folder.Name
    $folder.Subfolders | % { if( $.item -ne $null) { ListFolders $}}
    }

    ListFolders $list.RootFolder

    I hope this information helps. If you have any questions please let me know and I will be glad to help you out.

    ------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer--


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.