Restore the specified file version using SharePoint 2010 web service in powershell

Steps Involved:

  1. Open SharePoint 2010 Management Shell by going to Start | All Programs | SharePoint | Microsoft SharePoint 2010 Products | SharePoint 2010 Management Shell (Run as Administrator).
  2. Run the following script.

Powershell Script:

 
## Restore the specified file version using SharePoint 2010 web service in powershell
$uri="http://serverName:10736/sites/ECT/_vti_bin/Versions.asmx?wsdl"
## $fileName is the string that contains the site-relative URL of the file
[
String]$fileName="Shared Documents/test.docx"
## $fileVersion is the string that contains the version that has to be restored
[
String]$fileVersion="5.0"

## Web Service Reference - http://Site/_vti_bin/Versions.asmx
$viewsWebServiceReference = New-WebServiceProxy -Uri $uri -UseDefaultCredential
[
System.Xml.XmlNode]$xmlNode=$viewsWebServiceReference.RestoreVersion($fileName,$fileVersion)