A little iteration trough all webs and all lists checking if versioning is enabled and if so setting majorversion limit to 2. Then you need to update each item to delete all other versions:
$site = Get-SPSite http://mycoolsitecollection
$webs = $site.AllWebs
foreach ($web in $webs) {
foreach($list in $web.Lists) {
if($list.EnableVersioning) {
$list.MajorVersionLimit = 2
$list.Update()
foreach($item in $list.Items) {
$item.SystemUpdate($false)
}
}
}
$web.Dispose()
}
Keep in mind: if you set limit to 2 there will be 3 versions visible when looking at version history (current and last 2).
Also if you have large lists foreach ($item in $list.Items) on items can take a while.