Quantcast
Channel: SharePoint Diary
Viewing all articles
Browse latest Browse all 1058

Export Document Library File-Folder-SubFolder Structure to CSV

$
0
0
Requirement:
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
}
}

#Variables
$WebURL="https://portal.crescent.com/sites/sales/"
$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!

Viewing all articles
Browse latest Browse all 1058

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>