1

We are working on SP 2013 On Premise Environment. For archival process of old site collections, we are trying to find out site collections which have not been accessed since 1st Jan 2018 in a web application.

Using PowerShell for this, once we loop through all the site collections we are currently performing a check in the following manner :

foreach($sc in $webapplication | Get-SPSite -Limit All)
{
    if ($sc.RootWeb.LastItemModifiedDate -lt $lastDate)
    {
        Write-Host "Site is old…" + $sc.Title
        Add-Content -Path $outputPath -Value "$($sc.URL)"
    } 
}

However, the list of site collections which we get in this manner is not accurate since we have manually checked some site collections and found that they have not been updated in over a year and still they are showing up in the output. One possible explanation for this is due to the timer jobs which run on a farm level and so if for instance a user is removed or added the last item modified date for site collections change in this process.

Note: We need this only for site collections and not for Sub sites. For Sub sites we can do :

$su = Get-SPWeb -identity “Site collection url” 
$u. LastItemModifiedDate

And for Site Collection we can also use LastContentModifiedDate. However, that again does not give us accurate results.

Could anyone suggest if there is a workaround for the above problem, Any Thoughts/suggestions are welcome

0

What do you mean by "access", exactly? If you want to know the last time any content on a site was viewed then you might be able to get that from the standard Usage Reports.

For each sub site go to the "View Usage Reports" page, e.g. https://contoso.net/sites/subsiteA/_layouts/15/Reporting.aspx?Category=AnalyticsSite

(To see Site Collection Reports, change the Category parameter to AnalyticsSiteCollection.)

Depending on how many sites you have, it may be more efficient to find a programmatic way to do this. You could also install a JS tracker script in your master page that creates a new list item as soon as the page is loaded (here is an example of such a script). Or use Google Analytics, which is free but creates a security concern. From this you will, over time, get a very clear picture of how many times users are accessing each site.

EDIT: To check on whether any List Items (for example) on a given site collection have been Modified since a given date, we can do a KQL query that specifies the content type and the date range, and then see how many results we get. (Of course, this only works if all of your site collections are being indexed by the Search Service.)

If we get 0 results for a query like "List Items whose modified date is past 1/1/2018" then we can reasonably say that site's lists have not been modified since 1/1/2018. Then, we can enclose this in a loop to do the same check for every site collection:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Office.Server.Search.Query”)  

[String]$lastDate = "1/1/2018"

foreach($sc in $webapplication | Get-SPSite -Limit All)
{
    Write-Host $sc.Url -ForegroundColor Yellow

    $keywordQuery = New-Object Microsoft.Office.Server.Search.Query.KeywordQuery($sc)
    $keywordQuery.QueryText = "ContentClass:STS_ListItem AND LastModifiedTime>=$($lastDate) AND site:$($sc.Url)"
    $keywordQuery.RowLimit = 5;
    $searchExec = New-Object Microsoft.Office.Server.Search.Query.SearchExecutor
    $searchResults = $searchExec.ExecuteQuery($keywordQuery)

    If( 0 -eq $searchResults.Table.Count ){
        Write-Host "`tSite Collection $($sc.Url) is old" -ForegroundColor Red

}
1
  • Chris, Thanks for replying. By "access" I mean the last time any list/library item may have been modified. Comparing that with a specific date in my script and getting the site collection URL for all the matches. Also I'm looking for Site Collections Information and not Sub-site. As suggested by you, adding a JS tracker in master page is not really an option, since we have more than 200 site collections and some site collections use custom master pages.
    – Hank
    Nov 28 '18 at 15:04
0

I would suggest using "Web Analytics Reports".

1) Go to site settings and look for "Site Collection Web Analytics reports"

2) Open "Number of Daily Unique visitors"

3) In the notification bar press "Change Settings" to change the date range

4) Ribbon "Analyze" - button "More" - dropdown "Preceding 365 days" or choose a custom date range

Now You will see a chart with a count of unique visitors that have accessed Your site collection during the last 365 days (or custom date range).

Update: LastItemModifiedDate and LastContentModifiedDate does not represent a date, when anybody was accessing site, but when modifications are made. Out member Naim Murati has a good explanation about LastContentModifiedDate - check this answer .

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.