Aug 22 2023 12:32 AM
Hello everyone,
Can you please tell me if there is a way to get a report of inactive/unused sites from all SharePoint 2019 sites that I have in my farm?
I used PowerShell with the following two properties "LastUserModifiedDate" and"LastItemUserModifiedDate" but I don't think the .csv report that I got is that accurate.
Based on the following Microsoft article, https://learn.microsoft.com/en-us/sharepoint/troubleshoot/lists-and-libraries/modified-date-site-con... "LastItemUserModifiedDate" should be useful in this case.
Do you know or do you have any other solutions for this subject?
Thank you very much!
Aug 22 2023 02:04 AM
Hi @Mike9323,
the script you've provided is a good starting point, but it lacks the specific logic to determine site inactivity.
Below is the example PowerShell script (i haven't be able to test it) that hase more "advanced" criteria for identifying potentially inactive sites based on a combination of factors. You will need to customize the script to match your organization's needs and criteria for site inactivity.
# Connect to SharePoint
Connect-PnPOnline -Url https://your-sharepoint-site-url -UseWebLogin
# Get all sites
$sites = Get-PnPTenantSite
# Create an array to store inactive sites
$inactiveSites = @()
foreach ($site in $sites) {
$siteUrl = $site.Url
# Get site statistics
$siteStatistics = Get-PnPTenantSiteStatistics -SiteId $site.SiteId
# Define criteria for site inactivity (customize as needed)
$daysSinceLastActivity = (Get-Date) - $siteStatistics.LastActivityDate
$minimumDaysInactive = 90 # Adjust this value based on your criteria
if ($daysSinceLastActivity.Days -ge $minimumDaysInactive) {
$inactiveSites += [PSCustomObject]@{
SiteUrl = $siteUrl
LastActivityDate = $siteStatistics.LastActivityDate
DaysInactive = $daysSinceLastActivity.Days
InactiveReason = "No recent activity"
}
}
}
# Disconnect from SharePoint
Disconnect-PnPOnline
# Export the results to a CSV file
$inactiveSites | Export-Csv -Path "InactiveSitesReport.csv" -NoTypeInformation
What the script does (or trying to do)
Remember to adjust the $minimumDaysInactive value based on your definition of inactivity.
Before running the script, ensure you have the SharePoint PnP PowerShell module installed and configured. You can also download and try to use SharePoint Online Management Shell:
Download SharePoint Online Management Shell from Official Microsoft Download Center
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.
If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
Aug 22 2023 05:36 AM - edited Aug 22 2023 05:37 AM
Hello @LeonPavesic,
Thank you for your quick response but unfortunately what you provided I don't think that can help, because what I looking for is related to SharePoint 2019 and not to the SPO version.
If you have other solution about SP 2019 I would be happy to hear it 🙂
Cheers,
Mike