Link to home
Create AccountLog in
Avatar of jimmylew52
jimmylew52Flag for United States of America

asked on

Powershell script to return files more than two hours old.

I need a Powershell script to return files names in a directory that are more than two hours old. I can retrieve the file names but cannot get it to not report if the files are less than two hours old. Here is what I have:

$Dr_Path is a test file with the directory paths in it.

Get-ChildItem $Dir_Path | Where { $_.CreationTime.Date -lt (Get-Date).AddMinutes(-120)} | ? {! $_.PsIsContainer}
Avatar of kmslogic
kmslogic
Flag of United States of America image

It seems to work for me, what seems to be missing?
Avatar of jimmylew52

ASKER

It reports files that are less than 2 hours old. It reports files that are created in the last 10 minutes.
ASKER CERTIFIED SOLUTION
Avatar of kmslogic
kmslogic
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
That Works!!!

Thank You so much.