Hi can someone direct me for best way to generate site list based on last modified date? we have approximately 1500 Site collection in SharePoint 2007. The intention is to remove the unused sites.


Try this below PowerShell it will run for SharePoint 2013:

Add-PSSnapin Microsoft.sharepoint.powershell -ErrorAction SilentlyContinue 
$Webapp = "http://sp2013vm:5555/" 
$site = Get-SPSite -webapplication $Webapp -Limit All 
$site | Get-SpWeb -Limit All | Format-Table -Property LastItemModifiedDate,URL -AutoSize | Out-string -width 3000 > "C:\output_webapp.txt"

It will generate one txt file with all sub sites and sites along with last modified date.


Try this below script. It will run in SP2007:

#Set-ExecutionPolicy RemoteSigned
$site = New-Object Microsoft.SharePoint.SPSite($url)
$spWebApp = $site.WebApplication

$OutputFN = "c:\ActiveSitesReport.csv"
"Site Name `t URL `t Last Modified" > $OutputFN

# Iterate through all sites:
 foreach ( $spSite in $spWebApp.Sites )
         foreach ($spWeb in $spSite.AllWebs)
                  if ($spWeb.IsRootWeb)
                    $siteName = $spWeb.Title +" - Root";
                  $siteName = $spSite.RootWeb.Title + " - " + $spWeb.Title;

              $siteName + "`t" + $spWeb.Url + "`t" + $spWeb.LastItemModifiedDate >> $OutputFN

It will give one csv file.


  • Thanks for your reply. but in SharePoint 2007 Farm we cant run PowerShell commands are not specifically build for 2007. i can still try.
    – Viral
    Nov 25 '16 at 10:46
  • Have you tried this? Is it worked for you? Dec 2 '16 at 4:13
  • SharePoint 2007 one worked for me, Is there anyway we could append size of that site too? May 6 '19 at 14:10

You need to write custom server side code as it is 2007, powershell might not directly work. you will have to rely on SPWeb.LastItemModifiedDate property to check. below can get you started.. write a console utility which will run on server which will generate report for you.

// write you code logic here to loop through all site collection of a web application... if you are doing that below url won't be required.
     using(SPSite oSiteCollection = new SPSite("http://Server_Name"))
                using(SPWeb oWebsiteRoot = oSiteCollection.RootWeb)
                  DateTime lastModifieddate = oWebsiteRoot.LastItemModifiedDate;
                  //......... write your code logic here to put in text file
  • Thanks Siddharth, we will try running in test environment to get the results.
    – Viral
    Nov 25 '16 at 10:53
  • np..please upvote and mark it answer if it is useful... Nov 25 '16 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.