Find Files Modified After a Specific Date in SharePoint Library (PowerShell Script)
Have you ever struggled to locate files modified after a certain date in your SharePoint library? Scrolling endlessly or manually checking each file can be tedious and time-consuming. This manual process can lead to frustration, wasted time, and even errors if files are missed. Without a streamlined method, managing files in SharePoint becomes inconvenient, slowing down productivity and causing unnecessary stress.
In this guide, we’ll walk you through the process step-by-step with a custom PowerShell script to find files modified after a specified date in SharePoint, with this you can effortlessly pinpoint the exact files you need, streamlining your workflow and eliminating the hassle of manual searching.
Function getFilesWithin($list)
{
foreach($item in $list.Items)
{
if ($folderURL -ne “”)
{
if ($item.Url.StartsWith($folderURL, “CurrentCultureIgnoreCase”))
{
$targetFile = $item.file;
if ($targetFile.TimeLastModified -ge (Get-Date $lastDate)){
$item.Name + “;” + $item.Url + “;” + “File;” + $($targetFile.TimeLastModified).ToString(‘dd/MM/yyyy’) | Out-File $logWrite -Append
} else {
write-host -f green “Not changed after given date” + $item.Url
}
}
}
else
{
$targetFile = $item.file;
if ($targetFile.TimeLastModified -ge (Get-Date $lastDate)){
$item.Name + “;” + $item.Url + “;” + “File;” + $($targetFile.TimeLastModified).ToString(‘dd/MM/yyyy’) | Out-File $logWrite -Append
} else {
write-host -f green “Not changed after given date” + $item.Url
}
}
}
}
$snapin = Get-PSSnapin | Where-Object { $_.Name -eq “Microsoft.SharePoint.Powershell” }
if ($snapin -eq $null) {
Write-Host “[INIT] Loading SharePoint Powershell Snapin”
Add-PSSnapin “Microsoft.SharePoint.Powershell”
}
#****PARAMETRES DEFINITION****
#Specify web site URL wherein Document Library exists
$web= Get-SpWeb “http://w2k8sp2010dev01:13432/”
#Specify Title of Document Library
$DocLibName = “Shared Documents”
#Specify Folder URL if in case any specific documents within folder has to be worked upon or keep blank
$folderURL = “”
#Log File Name, will be suffixed by date time
$LogFileName = “Get_LibFiles_ModifiedAfter_Log”
#Specify date after which files modified should be extracted
$lastDate = “2015-01-30”
#****PARAMETRES DEFINITION****
$LogFileName = $($LogFileName) + “@” + $(Get-Date -format MMddyy) + “.csv”
write-host -f RED $LogFileName
set-variable -option constant -name logWrite -value $($LogFileName)
“File Name;File URL;Type;Last Modified” | Out-File $logWrite -Append
write-host -f White “Connected to Web”
$Lib=$web.Lists.TryGetList($DocLibName)
write-host -f White “Connected to Library”
if ($Lib.LastItemModifiedDate -ge (Get-Date $lastDate)){
write-host -f yellow “Changed after given date ” + $($Lib.LastItemModifiedDate)
} else {
write-host -f green “Not changed after given date”
}
getFilesWithin($Lib)
$web.Dispose();
**************SCRIPT ENDS HERE***************
Instructions to use the above Power-shell script;
You will need to change parameter values and below are the definition of parameters;
1. Web Site URL – Specify web site URL
2. Title of Document Library – Specify Document Library Name
3. Folder URL – Specify Folder URL starting with Library Name For E.g. “shared documents/folder name”
4. Log File Name – Specify Log File Name
5. Date after which files modified – Specify Date criteria (should be in format of “yyyy-mm-dd”)