0
votes

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.

please tell me how do I do that using a SharePoint PowerShell script.

1

1 Answers

0
votes

You could try the following script to copy documents' 4.0 to another library:

#Variables for Processing
$WebURL="http://sp2016"
$SourceFile="http://sp2016/Shared%20Documents/test.docx"
$TargetLibrary="doc1"

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

#Copy the file into the Target library
$TargetLibrary.Files.Add($File.Name, $Version4.OpenBinary(), $true)