Find unused sites based on Last Modified Date

I am preparing for SharePoint 2013 from SharePoint 2010. It is important for me to find out sites that have not been accessed in past 3 months. Idea is to notify to site owners to find out if those un-used sites can be archived and moved to different site collection (which is in a different content database).

So I wrote a powershell command to find out unused sites. Using this command I am finding Site Name, its relative Url, site author (who created the site) and lastitemModifiedDate date time when the site’s item was last accessed.

Input Parameters: (a) File name with location where output file can be created. (b) Last Accessed Date in mm/dd/yyyy format.

———————– PowerShell Command: StartĀ ———————

$outputPath = Read-Host “Outputpath (e.g. C:\output\UnusedSites.txt)”
$lastDate=Read-Host “Last Accessed Date (in format mm/dd/yyyy)”
$gc = Start-SPAssignment
$site=$gc | get-spsite -Identity https://sitecollectionUrl
foreach($web in $site.AllWebs)
if ($web.LastItemModifiedDate -lt $lastDate)
Write-Host -f Red “Site is old…” + $Web.Title
Add-Content -Path $outputPath -Value “$($web.Title),$($web.ServerRelativeUrl),
Write-Host -f Green “Site: [” + $web.Title + “] Last Modified Date: ” + $web.LastItemModifiedDate
Stop-SPAssignment $gc

—————— PowerShell Command: End ——————
Read-Host: To read/accept parameters from command prompt
Write-Host: Write results onto screen (powershell command screen)
Start-SPAssignment & Start-SPAssignment: To dispose objects and variables in the scope ($gc) defined
Add-Content: Writes the output to file.

In case if you want to display all the administrators assigned to site, here is the powershell command that can be added in the above script appropriately:

foreach($user in $web.SiteAdministrators)
Add-Content -Path $outputPath – Value “$($user.Name),$($user.LoginName),$($user.IsSiteAdmin)”


About Atul Shukla

Dynamics AX 365 for Operations based data migrations, synchronous and asynchronous integrations, extending data entities and customizing entities for data migrations and integrations. I am into Microsoft Dynamics AX 2012 data migration using SQL Server and DIXF framework. SharePoint is my part time passion where I get involved in designing of SharePoint Branding, Designing and challenging website issues where I then involve and brush up my troubleshooting skills using PowerShell. The blog has articles about the issues that I face randomly followed by the fixes. SharePoint 2010 works pretty differently when it integrates with Dynamics AX 2012/2009, BizTalk EDI Processes. Dynamics AX Reporting is also interesting so I do SSRS installation, configuration for Enterprise Portal and Role centers. Pretty interesting stuff - keeping me engaged all the time.
This entry was posted in PowerShell Command, SharePoint 2010. Bookmark the permalink.

6 Responses to Find unused sites based on Last Modified Date

  1. Vinod says:

    You are retrieving based on the last modified date and not the last accessed date. Do you have any idea how to retrieve the last accessed date of a site.

    • Atul Shukla says:

      By default, there isn’t any property available to achieve this. Instead it can be customized. You can write a custom web part or a site feature. In the site feature you can implement code to log last accessed date and time by a specific user. And then this information can be accessed via powershell. I have not done it, but it is a thought that would work.

  2. The title of this article is misleading.

    thank you, but please fix the title to “Find unused sites based on last MODIFIED date”, it is misleading this way.

    last modified does not mean last accessed

  3. Snehil Jain says:

    Hi Atul, PowerShall command shows that you are finding unused sites using last modified date. Is there a way to find sites using last accessed?

  4. Null Data says:

    I would suggest that finding last accessed date would be difficult – especially if you have search crawling the content of that site!

    You maybe be able to use site auditing to see if a site is being accessed, however it would not be easy to script!

    You may also be able to look through the IIS logs to find further information.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s