SharePoint Online: PowerShell kullanarak bir Belgenin Tüm Sürümlerini İndirin
Gereksinim: PowerShell kullanarak SharePoint Online'daki bir Belgenin Tüm Sürümlerini İndirin.
SharePoint Online: Bir Belgenin Tüm Sürümlerini İndirmek için PowerShell
SharePoint Online'da belgeler kitaplıklarda depolanır ve zaman içinde bir belgenin birden çok sürümünün bulunması yaygın bir durumdur. SharePoint Online'daki sürüm geçmişi, dosyaları değiştikçe kitaplıkta saklamanıza, izlemenize ve geri yüklemenize olanak tanır. Bazen bir dosyanın önceki tüm sürümlerini indirmeniz gerekebilir. Ancak bir belgenin tüm sürümlerini indirmek, özellikle bunu manuel olarak yapmanız gerekiyorsa sıkıcı bir süreç olabilir. Zamandan ve emekten tasarruf etmek için, SharePoint Online'daki bir belgenin tüm sürümlerini indirmek üzere PowerShell'i kullanabilirsiniz.
Bir dosyanın her sürümünün web kullanıcı arayüzünden indirilmesi zaman alıcı ve zahmetli olduğundan, CSOM kullanarak bir dosyanın tüm sürümlerini SharePoint Online belge kitaplığından indirmek için PowerShell'i burada bulabilirsiniz.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Parameters
$SiteURL = "https://Crescent.sharepoint.com"
$FileRelativeURL ="/Shared Documents/Discloser China.doc"
$DownloadPath= "C:\Temp"
#Get credentials to connect
$Cred = Get-Credential
#Setup the Context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName, $Cred.Password)
#Get the File and its versions
$File = $Ctx.Web.GetFileByServerRelativeUrl($FileRelativeURL)
$Ctx.Load($File)
$Ctx.Load($File.Versions)
$Ctx.ExecuteQuery()
If($File.Versions.Count -gt 0)
{
Foreach($Version in $File.Versions)
{
#Frame File Name for the Version
$VersionFileName = "$($DownloadPath)\$($Version.VersionLabel)_$($File.Name)"
#Get Contents of the File Version
$VersionStream = $Version.OpenBinaryStream()
$Ctx.ExecuteQuery()
#Create File version at local disk
[System.IO.FileStream] $FileStream = [System.IO.File]::Open($VersionFileName,[System.IO.FileMode]::OpenOrCreate)
$VersionStream.Value.CopyTo($FileStream)
$FileStream.Close()
Write-Host -f Green "Version $($Version.VersionLabel) Downloaded to :" $VersionFileName
}
}
Else
{
Write-host "No Versions Available for "$Item["FileRef"] -f Yellow
}
Bir Belgenin Tüm Sürümlerini Dışa Aktarmak için PnP PowerShell
SharePoint Online'dan bir dosyanın tüm sürümlerini indirmek için PnP PowerShell'i kullanalım:
#Set Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Funds"
$FileRelativeURL = "/sites/Funds/Funds/Reporting/External/QR/2019/Q3 2019/Global 4/Global IT Seg v2.xlsx"
$DownloadPath = "C:\Temp"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
$Ctx = Get-PnPContext
#Get the File
$File = Get-PnPFile -Url $FileRelativeURL
#Get File Versions
$FileVersions = Get-PnPProperty -ClientObject $File -Property Versions
If($FileVersions.Count -gt 0)
{
Foreach($Version in $FileVersions)
{
#Frame File Name for the Version
$VersionFileName = "$($DownloadPath)\$($Version.VersionLabel)_$($File.Name)"
#Get Contents of the File Version
$VersionStream = $Version.OpenBinaryStream()
$Ctx.ExecuteQuery()
#Download File version to local disk
[System.IO.FileStream] $FileStream = [System.IO.File]::Open($VersionFileName,[System.IO.FileMode]::OpenOrCreate)
$VersionStream.Value.CopyTo($FileStream)
$FileStream.Close()
Write-Host -f Green "Version $($Version.VersionLabel) Downloaded to :" $VersionFileName
}
}
Else
{
Write-host -f Yellow "No Versions Found!"
}
Özetle, SharePoint Online'da bir belgenin tüm sürümlerini indirmek için PowerShell'i kullanmak, belgelerinizde yapılan her değişikliği almanın kullanışlı ve etkili bir yoludur. PowerShell betiğiyle bir belgenin tüm sürümlerini hızlı bir şekilde alabilir, böylece değişiklikleri izlemeyi ve belge geçmişinin kaydını tutmayı kolaylaştırabilirsiniz.
