Power Shell: Remove files, subfolders older than X days
1. Power shell script to remove files and subfolders older than 30 days from directory "E:\directory\
Get-ChildItem -path "E:\directory\" -recurse | where-object {$_.LastWriteTime -lt (Get-Date).AddDays(-30)} | Remove-Item -Recurse -Force
2. Schedule script: E:\RemoveFiles.ps1
Action: Start a program
Program: PowerShell.exe
Add arguments (optiona): -ExecutionPolicy Bypass E:\RemoveFiles.ps1
No comments:
Post a Comment