Tuesday, April 15, 2008

PowerShell Directory Clean Up Script

Just a quick post of a PowerShell script I leveraged to clear out a directory of files older than 7 days. Props to Jeffery Hicks.
powershell.exe -command "Get-ChildItem 'C:\Temp\' -recurse | where {$_.LastWriteTime -le (Get-Date).AddDays(-7)} | remove-item -recurse"
Tack on a -whatif to the end of the script to see what would be affected without actually executing the action. Very powerful. PowerShell. Solid PowerShell cheat sheet here

No comments: