Get Inventory of All SharePoint Documents Using Windows PowerShell






4.86/5 (4 votes)
Get inventory of all SharePoint documents using Windows PowerShell.
I thought this was a great find when looking to assess site usage before planning data migration to SharePoint 2013. I haven’t run it across the entire farm yet due to the time it will take to run; however, I’ve tested it and posted the code below the link to show some changes I’ve made to get it to work in my environment. I encourage you to read the comments when following the link for some troubleshooting if you run into trouble.
Getting an Inventory of All SharePoint Documents Using Windows PowerShell « SharePoint Automation.
[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") [System.Reflection.Assembly]::Load("System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") function Get-DocInventory([string]$siteUrl) { $site = New-Object Microsoft.SharePoint.SPSite $siteUrl foreach ($web in $site.AllWebs) { foreach ($list in $web.Lists) { if ($list.BaseType -ne “DocumentLibrary”) { continue } foreach ($item in $list.Items) { $data = @{ "Site" = $site.Url "Web" = $web.Url "list" = $list.Title "Item ID" = $item.ID "Item URL" = $item.Url "Item Title" = $item.Title "Item Created" = $item["Created"] "Item Modified" = $item["Modified"] "File Size" = $item.File.Length/1KB } New-Object PSObject -Property $data } } $web.Dispose(); } $site.Dispose() } Get-DocInventory | Out-GridView Get-DocInventory | Export-Csv -NoTypeInformation -Path c:\Temp\Report_SC_Docs.csv