document listing/inventory using powershell

Few weeks back I faced a situation where i have to list all the documents in the site on a given day.  This was only possible either using C# and PowerShell.  I did some research and found some blog where I found a nice script.  I was not able to find the post again so I am putting the script below.  it may help someone.

[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” -or $list.Hiddden -eq $false -or $list.title -contains "Template" -or $list.title -contains "Master" -or $list.title -contains "Images" -or $list.title -contains "images" -or $list.title -contains "Template") {
        continue
}
#Add the login in the comments part if you want to filter the documents.
foreach ($item in $list.Items) {
    #$Modified = $item["Modified"]
    #Write-Host $Modified
    #if($Modified -gt $FRiday)
    #{
        $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/1024KB
        }
     #}
New-Object PSObject -Property $data
}
}
$web.Dispose();
}
$site.Dispose()
}

#You can use either a Grid View or csv File.
#Get-DocInventory "http://site.contoso.com" | Out-GridView
Get-DocInventory "http://site.contoso.com" | Export-Csv -NoTypeInformation -Path c:\DocsInventory.csv
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s