Thursday, July 10, 2014

Download All Document Versions using Web Services - PowerShell

Wanted to extract and download each version of the document stored in a SharePoint library. Well, PowerShell can do it from client side using web services. Here is the PowerShell script to download each version to the local folder programmatically.

# ******* Variables Section ******************
#Define these variables 
$FilePath =""
$TargetFolder = "C:\Downloads"
# *********************************************

#Web Service URL
$WebServiceURL =$WebURL+"_vti_bin/Versions.asmx"
$WebService = New-WebServiceProxy -Uri $WebServiceURL -UseDefaultCredential

#Get File name from file path
$FileName = $FilePath.Substring($FilePath.LastIndexOf("/")+1,($FilePath.Length-$FilePath.LastIndexOf("/")-1))

#Create the Target Library if it doesn't exists
    if (!(Test-Path -path $TargetFolder))
             #If it doesn't exists, Create
             $TargetFolder = New-Item $TargetFolder -type directory

#Call web service method "GetVersions" to retrieve versions collection
$FileVersions = $WebService.GetVersions($FilePath).Result
 foreach($File in $FileVersions)
  #Frame the File name : E.g. 1.0_Filename.ext
  $VersionFileName = "$($TargetFolder)\$($File.version)_$($FileName)"
  write-host $VersionFileName
  $webclient = New-Object System.Net.WebClient
     $webclient.UseDefaultCredentials = $true
  write-host $File.url
  Write-Host "Downloaded version: $($File.Version)"

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...