delete_files_older_than
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 -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt (Get-Date).AddDays(-30) } | Remove-Item -Force -Verbose
delete_files_older_than.txt · Last modified: 2024/10/17 21:42 by 127.0.0.1
