Sunday, February 4, 2018

Visit SharePoint sites to find LastItemModifiedDate using PowerShell

Copy below code and save to text file with extension *.ps1 and run on SharePoint server using SharePoint Management Shell Tool.

# add pssnapin
Add-PSSnapin Microsoft.SharePoint.PowerShell –erroraction SilentlyContinue

# add sharepoint DLL

# create objects for writing the output file
$objResults = @()
$objResults | Export-Csv -NoType $file
$objFile =  "C:\output.csv"
$objNewline = "{0},{1},{2}" -f "Site-Title","Site-URL", "Last-Item-Modified-Date"
$objNewline | add-content -path $objFile

# create object for site and provide sharepoint site URL
$objWebSite = Get-SPWebApplication "http://SHAREPOINT-SITE-URL"

# loop through sites and write the data to file
foreach($objSite in $objWebSite.Sites)
foreach($objWeb in $objSite.AllWebs)
$objNewline = "{0},{1},{2}" -f $objWeb.Title, $objWeb.Url, $objWeb.LastItemModifiedDate
$objNewline | add-content -path $objFile

# use exit if you only need data on site collection level, remove if you need data on each site and sub-site level

No comments:

Post a Comment