At the SharePoint Conference 2011 I had a discussion with Christian Ståhl and Laura Curtis if it will be possible to cleanup old versions in SharePoint using a script or command line application. I thought to myself that this should be a big task to accomplish but a useful. The slow way to clean up old versions is to loop through all the site collections, webs, lists and items. From each item check the versions and delete them. In SharePoint 2010 Server there is a much smarter way to do this by using a helper that exists in SharePoint Server. The class I’m talking about is called ContentIterator and can be found in Microsoft.SharePoint.Server.Utilities namespace.
The smart thing about the ContentIterator it prevents SharePoint from blocking the database with requests. The only side effect of this is that items in the meantime can be modified because this method is not thread safe.[Read more]