Hello Louis
Welcome to the Microsoft Community.
Regarding the modification date attribute of the file you mentioned, you can refer to the following link:
Description of NTFS date and time stamps for files and folders
It's a pity that in the Windows system, we cannot manually intervene in the attributes of files. You can try to handle it through the following script.
#Set Parameters
$sourceRoot = "D:\PatientData"
$backupRoot = "Z:\Backups\June2025"
$cutoffDate = Get-Date "2024-04-01"
$maxBatchSize = 50
$logFile = "$backupRoot\backup_log.txt"
#Create a log file
New-Item -Path $logFile -ItemType File -Force | Out-Null
"Add-Content-Path $logFile-Value" Backup start time: $(Get-Date)"
#Obtain all patient folders
$patientFolders = Get-ChildItem -Path $sourceRoot -Directory
#Initialize the counter
$batchCount = 0
foreach ($folder in $patientFolders) {
$folderPath = $folder.FullName
#Check if there are any files in this folder that have been modified after cutoffDate
$recentFiles = Get-ChildItem -Path $folderPath -Recurse -File | Where-Object { $_.LastWriteTime -gt $cutoffDate }
if ($recentFiles.Count -gt 0) {
#Build the target path
$relativePath = $folder.FullName.Substring($sourceRoot.Length)
$targetPath = Join-Path $backupRoot $relativePath
#Create the target folder
New-Item -Path $targetPath -ItemType Directory -Force | Out-Null
#Copy the entire patient folder
robocopy $folder.FullName $targetPath /E /COPYALL /R:1 /W:1 | Out-Null
#Write Log
Add-Content-Path $logFile-Value "Backed up: $folderPath"
$batchCount++
If the batch limit is reached, pause and give a prompt
if ($batchCount -ge $maxBatchSize) {
"Writing-host" has copied $batchCount folders. Please check and continue to run the script to copy the next batch.
"Add-Content-Path $logFile-Value" is paused at: $(Get-Date), and $batchCount folders have been copied.
break
}
}
}
"Add-Content-Path $logFile-Value" Backup end time: $(Get-Date)"
"Write-Host" Backup completed. The log file is located at: $logFile"
Best Regards,
Henry-N - MSFT | Microsoft Community Support Specialist