0

Using either Powershell or other method, I need to export a list of titles of files, their filenames with extensions, their locations, and their URLs into a text or Excel file. This is what I have found so far (for Powershell):

Get-SPWeb https://tenant.sharepoint.com/ |
  Select -ExpandProperty Lists |
    Where { $_.GetType().Name -eq “SPDocumentLibrary” -and
            -not $_.Hidden } |
    Select -ExpandProperty Items |
    Where { $_.Url -like “*Documents*” } |
    Select Name, {$_.File.Length}, url

However, I need something that will give me the information I seek and will look recursively. I looked up the Select-Object and -ExpandProperty in SharePoint documentation, but I couldn't find what my options were for other properties I could choose. Also, I am looking to return all files, not just ones with a specific term in them.

Please help, if you can! Thanks, in advance!

  • While a single long pipeline has it's benefits, you loose acces to former stages properties with each select (-ExpandProperty). Either use a -PipelineVariable or split by using variables for intermediate results. – LotPings Jun 8 at 8:18
0

For SharePoint Online, we can use CSOM with PowerShell to achieve it, the following example Script for your reference.

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

##Variables for Processing
$SiteUrl = "https://tenant.sharepoint.com/sites/lz"
$ListName="DL"
$ExportFile ="c:\temp\AllFiles.csv"
$UserName="lz@tenant.onmicrosoft.com"
$Password ="Your Password"

#Setup Credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))

#Set up the context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Context.Credentials = $credentials

#Get the List
$List = $Context.web.Lists.GetByTitle($ListName)

#Get All List Items
$Query = New-Object Microsoft.SharePoint.Client.CamlQuery
$Query.ViewXml = '<View Scope="RecursiveAll"><Query><Where><Eq><FieldRef Name="FSObjType" /><Value Type="Integer">0</Value></Eq></Where><OrderBy><FieldRef Name="ID" /></OrderBy></Query></View>'
$ListItems = $List.GetItems($Query)
$context.Load($ListItems)
$context.ExecuteQuery()

#Array to Hold List Items
$ListItemCollection = @()

#Fetch each list item value to export to excel
$ListItems | foreach {
    $ExportItem = New-Object PSObject
    $ExportItem | Add-Member -MemberType NoteProperty -name "Title" -value $_["Title"]
    $ExportItem | Add-Member -MemberType NoteProperty -Name "Name" -value $_["FileLeafRef"]
    $ExportItem | Add-Member -MemberType NoteProperty -Name "URL" -value $_["FileRef"]
    #Add the object with above properties to the Array
    $ListItemCollection += $ExportItem
 }
#Export the result Array to CSV file
$ListItemCollection | Export-CSV $ExportFile -NoTypeInformation

Write-host "List data Exported to CSV file successfully!"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.