Automated file deletion #01


new-psdrive -name SomeFolder -psprovider FileSystem -root \\SomeShare\SomeFolder
$drive = new-object -com
$drive.MapNetworkDrive(“x:”, “\\SomeShare\SomeFolder”)

$EnumerateOpen = Get-ChildItem o:\ -recurse -include .DS_Store -force
foreach($FileName in $EnumerateOpen)

remove-psdrive -name SomeFolder



As with my previous post, this script does nothing apart from delete irritating files that do nothing apart from waste space. In this case, it’s the lovely .DS_Store files that Mac OS X throws around with glee. I’ve got a feeling you can put loads of file types in one script, but I’ve got a script per file type to (a) make testing easier- didn’t want to risk accidentally wiping out more than I’d intended and (b) to make it easier for others to follow.

Remeber that although your .DS_Store is “only” 7KB in size, it’s probably taking up way more space than that because file systems have minimum block sizes. According to this link-– any Windows OS from the last 12 years will default to a minimum block size of 4KB, so that 7KB file is already wasting 1KB of space. Multiply that by the number of .DS_Store files lying around and that’s a lot of wasted space. Add in all those accidentally created .lnk files, thumbs.db etc- just bin ’em.