Link to home
Start Free TrialLog in
Avatar of rimmena
rimmena

asked on

Powershell script to delete files older than x hours

I have a script that can move files based on x hours to another directory. I want to adjust it so that instead of moving the files, it deletes them.
dir "e:\test" *.log |select name, fullname, Path, LastWriteTime , @{Expression={((get-date) - $_.CreationTime).TotalHours};Name="Hours"} | Where {$_.Hours -ge 72} | ForEach{$m="e:\test\archive" + $_.Name;move $_.FullName $m}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Alan_White
Alan_White
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial