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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

$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

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

i wanna check New folder2 whether it is getting updated in last one hour
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Define "getting updated"
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.
Nandha Kumar BAuthor Commented:
sorry under Newfolder2
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

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

From novice to tech pro — start learning today.