Reputation: 7625
$PathToFolder = "D:\SCAN\iPhoneDepartment"
$limit = (Get-Date).AddDays(-7)
Get-ChildItem -Path $PathToFolder -Include *.* -File -Recurse | ? {
-not $_.PSIsContainer -and $_.CreationTime -lt $limit
}| foreach { $_.Delete()}
This is my code and it runs without any errors but it's not removing files that are older than 7 days.
Upvotes: 2
Views: 1004
Reputation: 36
Maybe you're trying to delete files that haven't changed in 7 days?
Get-ChildItem -Path $pathToFolder -File -Recurse | ? LastWriteTime -LE $limit | Remove-Item
Upvotes: 1