0

I have a source document library, with varying versions for each document. let's say there is a document in the library that has versions 6.0, 5.0, 4.0. The current version of this document is 6.0.

I want to copy the document's 4.0 version to another target document library using a sharepoint PowerShell script

Aziz Qureshi
  • 483
  • 1
  • 6
  • 17

2 Answers2

1

Please try the script below, change the required parameter to yours. And change the version number to the one you need.

#Variables for Processing
$WebURL="your site url"
$SourceFile="your file path"
$TargetLibrary="target library name"

#Get Objects
$Web = Get-SPWeb $WebURL
$File = $Web.GetFile($SourceFile)
$Version4=$File.versions.GetVersionFromLabel("1.0")
$TargetLibrary = $Web.GetFolder($TargetLibrary)

#Copy the file into the Target library
$TargetLibrary.Files.Add($File.Name, $Version4.OpenBinary(), $true)
Jerry_MSFT
  • 4,220
  • 1
  • 6
  • 11
0

If you open the version history of any document, you will find each older version have a URL like http://xxxxx/_vti_history/xxxxx . By providing the right URL your script can download specific version directly. Then upload to another library.

There is a good PowerShell sample script here please refer to this old thread.

Mark L
  • 4,065
  • 7
  • 66
  • 128