I am using sp 2010. I have a document library. I would like to go to one previous version of all the documents in this document library. Maybe in powershell? Something like a foreach loop and for each document go to the previous version?
1 Answer
$web = Get-SPWeb -Identity http://sp2010
$list = $web.Lists["Documents"]
$items = $list.Items
foreach ($item in $items)
{
$file = $item.File
$fileVersions = $file.Versions
if ($fileVersions.Count -gt 0)
{
$fileVersions.Restore($fileVersions.Count - 1)
}
}
UPDATE
Please note that when any of previous versions is restored a new version is created.
-
-
this script is not working. It creates a new version, but dont changes any metadata. What to do now?– OlaNov 21, 2014 at 14:41
-
-
I would like to go from version 0.2 to 0.1. That is not possible with your script because there is a check : if version is greater then 1– OlaNov 21, 2014 at 15:17
-
1Ok, sorry you need to remove the checkout and checkin code. I have updated the code. Try now Nov 24, 2014 at 12:50