当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 下载 SharePoint 中文档的所有版本 - Web 服务

作者:精品下载站 日期:2024-12-14 13:49:07 浏览:15 分类:玩电脑

使用 PowerShell 下载 SharePoint 中文档的所有版本 - Web 服务


要求:
我想要提取并下载存储在 SharePoint 库中的文档的每个版本。那么,PowerShell 可以使用 Web 服务从客户端完成此操作。以下是用于以编程方式将每个版本下载到本地文件夹的 PowerShell 脚本。

使用 PowerShell 下载文档的所有版本


# ******* Variables Section ******************
#Define these variables 
$WebURL="https://sharepoint.crescent.com/sites/Operations/"
$FilePath ="https://sharepoint.crescent.com/sites/Operations/docs/designDoc.docx"
$TargetFolder = "C:\Downloads"
# *********************************************

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

#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
    $webclient.DownloadFile($File.url,$VersionFileName)
    Write-Host "Downloaded version: $($File.Version)"
}

输出如下所示:

[玩转系统] 使用 PowerShell 下载 SharePoint 中文档的所有版本 - Web 服务

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯