I was tasked with finding a way to programatically traverse all the document lbraries in a site collection and ​return the documents as well as some specific information about it.

I knew that I could put that together really quickly using the Get-SPSite cmdlet. And as soon as I got ready to open Powershell I remembered that this was a SP2007 machine. 🙁 All my super fast solutions went out the door as I realized m Get-SPSite cmdlt and others were not going to be available.

Well I knew I could probably do the same thing, but I’d have to pull out the glue and duct tape to build it without my precious Sp2010 Powershell cmdlts.

Before I turned back time and recreated the wheel I figured I’d take a quick look online and see if some one had previously dealt with this same situation but on a SP2007 scale, and sure enough one of my favorite SharePoint Automation guys Gary Lapointe had a blog post about it. (Short intermission, if you have twitter and aren’t following Gary Lapointe @glapointe I’d highly encourage you to do so, as well as often frequent his blog Sharepoint Automationhttp://blog.falchionconsulting.com/

His post stepped out how to build a function that actually runs against the entire farm and traverses all the document libraries on every site, web, under every web application in the farm. Well that was a little bit more than I needed but I was able to modify the script a bit to include just the site collection, that’s to some nifty comments. I was also able to add my own touch since I figured we’d be using this script open against other site collections, so I added a read-host parameter to prompt you for the site collection name you want it to return the report on.  Anyways I’ve posted my script below, please be gracious on my spacing issues and happy Sharepointing!

——————————————————————————

#Original Code provided by Gary Lapoint
http://blog.falchionconsulting.com

[void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)

function Get-DocumentLibraryInventory([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()
}

$sitecollection = read-host “Enter Site Collection Url”

#Get-DocumentLibraryInventory “http://sp2007” | Out-GridView
Get-DocumentLibraryInventory $sitecollection  | Export-Csv -NoTypeInformation -Path Report_SC_Docs.csv

————————————————————————————————————–

 

Gary’s full blog post is below.

http://blog.falchionconsulting.com/index.php/2010/08/getting-an-inventory-of-all-sharepoint-documents-using-windows-powershell/

(940)