From time to time, when I force-shutdown a Windows Server 2003 machine (I have no choice), the folders contained in a certain directory all change their 'modified date' to the current date.
Luckily, inside each of these folders, the files are all with the correct 'modified date'.
One of these files I want to copy the "modified (or created) date" with is a .jdf file that each of the folders has inside.
I need help to create a script in PowerSell.
I found this PS1 script that almost does the job:
Get-ChildItem $root | Where-Object {$_.PSIsContainer} | Foreach-Object{
# get the oldest file for the current directory object
$oldest = Get-ChildItem $_.FullName | Sort-Object LastWriteTime | Select-Object LastWriteTime -Last 1
if($oldest)
{
# oldest object found, set current directory LastWriteTime
$_ | Set-ItemProperty -Name CreationTime -Value $oldest.LastWriteTime
$_ | Set-ItemProperty -Name LastWriteTime -Value $oldest.LastWriteTime
}
else
{
# current directory is empty, directory LastWriteTime is left unchanged
Write-Warning "Directory '$($_.FullName)' is empty, skiping..."
}
}
The problem is that the last modified object inside the folders sometimes are subfolders that also get the current date as 'modified date'. How can I make it look the files inside the folder and not the folders?
NTFS
date and time stamp for a particular folder changes whenever an object (file or folder) is either created or deleted inside it.