Friday, November 20, 2015

Export Document Library File-Folder-SubFolder Structure to CSV

Get the complete structure of all folders-subfolder-files from a SharePoint document library and export to CSV file.

PowerShell Script to Iterate through each folder and Sub-folder and get all files:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

#Custom Function to get all files of a folder
Function GetFiles-ByFolder([Microsoft.SharePoint.SPFolder]$Folder)
    write-host "Processing Folder:"$Folder.URL
    Foreach($File in $Folder.Files)
        $content = $Folder.Name + "," + $Folder.URL +"," + $File.Name
        Add-content $OutPutFile $content
        Write-host $content
$ListName="Team Docs"
$OutPutFile = "C:\LibraryFiles.csv"

#Delete the file if exists
If (Test-Path $OutPutFile) { Remove-Item $OutPutFile }

#Write CSV headers
Add-Content $OutPutFile "Root Folder, URL, File Name"

#Get site object
$Web = Get-SPWeb $WebURL
$List = $Web.Lists[$ListName]
$Folder = $List.RootFolder

#Call the function for Root folder
GetFiles-ByFolder $Folder

#Call the function for each subfolder - Excluding "Forms"
$folder.SubFolders | Where {$_.Name -ne "Forms" } | foreach-Object {
    #Call the function Recursively!
    GetFiles-ByFolder $_
This exports the inventory of all files and folders structure to a CSV file!

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...