Here is a code to delete files older than N days where N refers number of days. In the code snippet below we are deleting files older than seven days.
$LastWrite
= (
Get-Date
).AddDays(-7)
Get-ChildItem
"C:\temp"
-Recurse
| Where {
$_
.LastWriteTime
-le
$LastWrite
} |
foreach
(
$_
) {
Remove-Item
$_
.fullname}
No comments:
Post a Comment