Why you should not use the ConfigMgr rebuild index task — Steve Thompson [MVP]

Rebuilding the database indexes is a good thing, yes? Absolutely. Why not use the ConfigMgr rebuild index maintenance task? When the maintenance task works, and I have proof that some of the time it fails to run on ConfigMgr: It REINDEXES all indexes with more than 10% fragmentation It does not update statistics Let’s break […]

via Why you should not use the ConfigMgr rebuild index task — Steve Thompson [MVP]

PowerShell – Find & Remove Files/Folders Older Than X Days

Ever wanted to purge all files and folders based on their creation date?. In my work environment we wanted to do just that, and depending on the location we needed to specify different retention lengths hence the following simple but effective PS script:

$dir = "\\FILESERVER\SHARETOINSPECT\"
$day = "365"
Get-ChildItem -Path $dir | Where-Object {$_.PSIsContainer -eq $true -and $_.CreationTime -lt (get-date).adddays(-$day)} | Remove-Item -Recurse -Force -Verbose

In the above example I have specified 365 days as the variable, however you can modify this using years, hours etc. Running the above script will result in all files and folders with creation dates older than the specified max being purged from the system.

As always use with caution and ensure you have backups.