PowerShell SharePoint 2007 get all sites, lists, item counts, last modified

I needed to run a script on a MOSS SharePoint 2007 server to get an idea of the amount of stuff to migrate. Most of the scripts I found online were useless. This code has been run in proper environments and works well. 

#clear the PowerShell window

#Set or reset default properties
$ReportPath = "C:\SPSiteReport.csv"
$webAppURL = ""

# Exclude the following libaries / lists
$excludeLists = @("Master Page Gallery",
                "User Information List",
                "Theme Gallery",
                "Style Library",
                "Solution Gallery",
                "Reusable Content",
                "Reporting Templates",
                "Reporting Metadata",
                "Long Running Operation Status",
                "List Template Gallery",
                "Content and Structure Reports",
                "Cache Profiles",
                "Workflow History",
                "Web Part Gallery",
                "Form Templates",
                "Workflow Tasks",
                "Suggested Content Browser Locations",
                "Site Template Gallery",
                "Variation Labels",
                "Content type publishing error log",
                "Converted Forms"

#Load the PowerShell commandlets for SharePoint using PowerShell 1.0 and MOSS 2007 compatibility

#Print the header in the resulting file
$Header = "Site Collection URL`tWeb Title`tWeb URL`tWeb Template`tList Title`tList Default View URL`tList Type`tItem Count`tList Last Modified"
Out-File -inputobject $Header -filepath $ReportPath -Force

function RecurseWeb($inSite) {
     foreach ($web in $inSite.AllWebs) {         
			foreach ($list in $web.Lists)
                if ($excludeLists -notcontains $list.Title)
    				#Get the count of items in the current list
                    $itemCount = $list.Folders.Count + $list.Items.Count
    				Write-Progress -activity "Inventorying items. . ." -status "Processing items in Site> $web - List> $list"
    			    #Output the result of the current list
    				$Result = $siteColURL + "`t" + $web.Title + "`t" + $web.URL + "`t" + $web.WebTemplate + "`t" + $list.Title + "`t" + $($web.URL + "/" + $list.DefaultView.Url) + "`t" + $list.BaseType  + "`t" + $itemCount + "`t" + $list.LastItemModifiedDate
    				Out-File -inputobject $Result -filepath $ReportPath -append

   $webApp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($webAppURL)

   foreach ($site in $webApp.Sites) {
        $siteColURL = $site.Url
        RecurseWeb $site


Leave a Reply

Your email address will not be published. Required fields are marked *