Skip to main content

Posts

Showing posts with the label scripting

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 . 

PowerShell: Alternative to VBScript and DOS Scripts

Most developers I know still use VBScript and DOS to compose reusable and one-time scripts. I was one of these people until I discovered PowerShell . It's a bit tricky to pick up but far more powerful than the legacy alternatives. My favorite feature is the "-whatIf" flag found on most (if not all) operations. One can set this flag to understand exactly what would happen if you were to execute the command as it is written. It's almost like having a unit test harness for scripting operations. No more accidental hard drive formatting. So, for your next scripting task, check out PowerShell instead of writing some hard-to-maintain/author legacy script.