need to check whether a particular folder under some particular path has updated in last one hour.

need to check whether a particular folder under some particular path has updated in last one hour.
Nandha Kumar BAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
$CompareDate = (Get-Date).AddHours(-1)
If ($Items = Get-ChildItem -Path C:\Particular\Folder -File | Where-Object {$_.LastWriteTime -gt $CompareDate}) {
	Write-Host "Folder was updated during the last hour."
}

Open in new window

0
Nandha Kumar BAuthor Commented:
above script is not working for particular folder
0
Nandha Kumar BAuthor Commented:
D:\New folder\New folder2

i wanna check New folder2 whether it is getting updated in last one hour
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

oBdACommented:
Define "getting updated"
0
Nandha Kumar BAuthor Commented:
there are many files under that particular folder

every minute files will be created under "D:\New folder\New folder2" so i need to monitor whether the files are created in last one hour under the folder New folder.
0
Nandha Kumar BAuthor Commented:
sorry under Newfolder2
0
oBdACommented:
Define "script is not working for particular folder".

This creates a temporary folder with two files, sets the LastWriteTime of one of them two hours into the past, and shows that the newer one was created inside the last hour:
$Folder = "${ENV:Temp}\TempFoo"
New-Item -Path $Folder -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
(New-Item -Path "$($Folder)\foo_old.txt" -ItemType File -Force).LastWriteTime = (Get-Date).AddHours(-2)
New-Item -Path "$($Folder)\foo_new.txt" -ItemType File -Force | Out-Null
gci $Folder | select Name, LastWriteTime | ft -au | Out-String | Write-Host -Fore Yellow

$CompareDate = (Get-Date).AddHours(-1)
If (($Items = Get-ChildItem -Path $Folder -File | Where-Object {$_.LastWriteTime -gt $CompareDate})) {
	Write-Host "The following files were updated in the last hour:"
	$Items | select Name, LastWriteTime | ft -au | Out-String | Write-Host -Fore Yellow
}
Remove-Item -Path $Folder -Recurse -Force

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.