SharePoint On-Premises : PowerShell script to find out last content modified of all site collections in a web application – required in SharePoint migration

Hi All,
Greetings for the day 🙂 LIFE IS BEAUTIFUL 🙂
Today one more PowerShell script required while doing migration
Use case :
- We are migrating our SharePoint 2013 On-Premises web application to SharePoint Online
- We are migrating content and plus new development to SharePoint Online
- In On-Premises environment we have around 200+ my site collections
- Since now users are started using there OneDrive for business, no need to migrate my site collections
- But we just need to verify once that is there any latest activity recently happen by users on their respective my site collections
- Hence the requirement born 🙂
Note : I am sharing here basic steps, you can make it more advanced by adding logs / making parameterized
Our approach :
Of course PowerShell script to scan through all my site collections and find out “LastContentModifiedDate“, “LastSecurityModifiedDate” and export to CSV file
Detailed steps :
- Add Microsoft SharePoint snap-in to the current session of PowerShell
Add-PsSnapin Microsoft.SharePoint.PowerShell
- The Start-SPAssignment cmdlet properly disposes of objects used with variable assignments.
Start-SPAssignment -Global
- CSV file path where we need to export
#CSV file path
$path = "D:/Knowledge Junction/PowerShell Scripts/mysiteslastmodifieddetails.csv"
- Fetch the web application – here in our case – My Site web application
#Fetch web application
$webApp = Get-SPWebApplication -Identity "https://mysite.knowledgejunction.com/"
- Create empty array variable to store the result
#create empty array variable - to store the result
$Report = @()
- Loop through all the site collections of above web applications and fetch the respective properties and store in object
foreach($spSite in $webApp.Sites)
{
#$spSite.LastContentModifiedDate
#$spSite.LastSecurityModifiedDate
$objSiteData = New-Object Pscustomobject -Property @{
SiteURL = $spSite.URL
LastModifiedDate = $spSite.LastContentModifiedDate
LastSecurityModifiedDate = $spSite.LastSecurityModifiedDate
Owner = $spSite.Owner
}#object
$Report += $objSiteData
#displaying site URL in console
Write-Host "Site - " $spSite.Url
Write-Host " "
}#foreach
- Finally export result to CSV file
$Report | Export-Csv $Path -NoTypeInformation
Complete PowerShell script :
#PowerShell script to get last modified properties of site collection from give web application
#Add Microsoft SharePoint snap-in to the current session of PowerShell
Add-PsSnapin Microsoft.SharePoint.PowerShell
#The Start-SPAssignment cmdlet properly disposes of objects used with variable assignments.
Start-SPAssignment -Global
#CSV file path
$path = "D:/Knowledge Junction/PowerShell Scripts/mysiteslastmodifieddetails.csv"
#Fetch web application
$webApp = Get-SPWebApplication -Identity "https://mysite.knowledgejunction.com/
#create empty array variable - to store the result
$Report = @()
foreach($spSite in $webApp.Sites)
{
#$spSite.LastContentModifiedDate
#$spSite.LastSecurityModifiedDate
$objSiteData = New-Object Pscustomobject -Property @{
SiteURL = $spSite.URL
LastModifiedDate = $spSite.LastContentModifiedDate
LastSecurityModifiedDate = $spSite.LastSecurityModifiedDate
Owner = $spSite.Owner
}#object
$Report += $objSiteData
#maintain the the logs
Write-Host "Site - " $spSite.Url
Write-Host " "
}#foreach
#export the result to CSV file on given path
$Report | Export-Csv $Path -NoTypeInformation
On Knowledge-Junction you will find lots of PowerShell script required for SharePoint Migration, SharePoint On-Premises and Microsoft 365. Please either search or find at – https://knowledge-junction.in/category/technology-articles/powershell-cmdlets/
Thanks for reading 🙂 HAVE A GREAT TIME AHAEAD 🙂
You must log in to post a comment.