delete_files_older_than
This is an old revision of the document!
You can use the Get-ChildItem cmdlet to retrieve the files, and the Where-Object cmdlet to filter the files based on their age. You can then use the Remove-Item cmdlet to delete the filtered files
Get-ChildItem -Path C:\path\to\folder -Recurse -File | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-90) } | Remove-Item –Force -Verbose
Get-ChildItem -Path C:\inetpub\mailroot\Badmail.old -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt (Get-Date).AddDays(-90) } | Remove-Item -Force -Verbose
delete_files_older_than.1676857123.txt.gz · Last modified: 2024/10/17 21:42 (external edit)
