Recently, I had a task to create a list of all documents uploaded into a certain SharePoint site. You might that this isn’t a hard task, but, when you have dozens of libraries all containing hundreds of documents things can get complicated.
To help me, I created a function called Get-Documents which which can be seen below :
function Get-Documents ()
{
Add-PSSnapin Microsoft.SharePoint.PowerShell
$web = get-spweb (Read-Host "Enter Site URL")
foreach ($list in $web.Lists)
{
if ($list.BaseType -eq "DocumentLibrary")
{
foreach ($item in $list.Items)
{
$data = @{
"Web" = $web.Url
"list" = $list.Title
"Item ID" = $item.ID
"Item URL" = $item.Url
"Item Title" = $item.Title
"Item Name" = $item.Name
"Item Created" = $item["Created"]
"Item Modified" = $item["Modified"]
"File Size" = $item.File.Length/1KB
}
New-Object PSObject -Property $data
}
}
$web.Dispose();
}
}
Get-Documents | Out-GridView
#Get-Documents | Export-Csv -NoTypeInformation -Path c:\temp\inventory.csv
This function extracts all relevant (for me) information about each document, (from all document libraries) and output’s it into a custom object.
Later you can take results and put it in grid view or export it to csv file. In my example, I output the list of SharePoint documents to a CSV file called “Inventory.csv”
