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
—————— 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)”