Skip to content

Instantly share code, notes, and snippets.

@joerodgers
Created November 14, 2019 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joerodgers/8f1f64f14a831ffb2d18cf407a3ea900 to your computer and use it in GitHub Desktop.
Save joerodgers/8f1f64f14a831ffb2d18cf407a3ea900 to your computer and use it in GitHub Desktop.
$web = Get-SPWeb -Identity "https://sharepoint.2016.contoso.com/sites/teamsite"
$Library = $web.Lists.TryGetList("Documents")
$query = New-Object Microsoft.SharePoint.SPQuery
$query.ViewXml = "<View Scope='RecursiveAll'>
<Query>
<Where>
<Eq>
<FieldRef Name='FSObjType'/>
<Value Type='Lookup'>0</Value>
</Eq>
</Where>
<OrderBy Override='TRUE'>
<FieldRef Name='FileLeafRef' />
</OrderBy>
</Query>
</View>"
$results = @()
$c = 1
do
{
$batch = $Library.GetItems($query)
$query.ListItemCollectionPosition = $batch.ListItemCollectionPosition
foreach( $b in $batch )
{
$results += [PSCUstomObject] @{
"#" = $c
FileName = $b.Name
FilePath = $b.File.ServerRelativeUrl
}
$c++
}
}
while($batch.ListItemCollectionPosition -ne $null)
$results | Export-Csv -Path "LibraryFiles.csv" -NoTypeInformation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment