Click here to Skip to main content
15,912,756 members
Articles / Operating Systems / Windows
Technical Blog

Get Inventory of All SharePoint Documents Using Windows PowerShell

Rate me:
Please Sign up or sign in to vote.
4.86/5 (4 votes)
31 Oct 2013CPOL 17.5K   3  
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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Systems / Hardware Administrator
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --