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

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)
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.