Tìm kiếm trang web

SharePoint Online: Bật lập phiên bản trên tất cả danh sách và thư viện bằng PowerShell


Yêu cầu: Bật Lập phiên bản trên tất cả các danh sách trong trang SharePoint Online.

Làm cách nào để bật tính năng lập phiên bản trên danh sách hoặc thư viện trong SharePoint?

Tính năng Lịch sử Phiên bản trong SharePoint cho phép bạn truy cập vào bản sao đã lưu trước đó của tài liệu hoặc mục danh sách. Theo mặc định, lập phiên bản được bật trên thư viện tài liệu của bạn trong SharePoint Online. Khi thao tác lưu diễn ra, SharePoint sẽ tạo một phiên bản mới cùng với siêu dữ liệu chẳng hạn như ai đã lưu mục, thời điểm nó được tạo, v.v. Để bật lập phiên bản cho danh sách hoặc thư viện trong SharePoint Online, hãy làm theo các bước sau:

  1. Chuyển đến thư viện tài liệu của bạn >> Nhấp vào tab Thư viện trên Ribbon >> Nhấp vào Cài đặt thư viện.
  2. Trong Cài đặt chung, hãy nhấp vào liên kết Cài đặt lập phiên bản.
  3. Từ trang Cài đặt lập phiên bản, chọn “Tạo phiên bản chính”. Tùy chọn, bạn có thể đặt giới hạn về số lượng phiên bản.

  4. Điều này cho phép lập phiên bản thư viện tài liệu SharePoint Online. Sau khi tính năng lập phiên bản được bật, bạn có thể chọn tài liệu hoặc mục danh sách và nhấp vào “Lịch sử phiên bản” từ menu ngữ cảnh hoặc từ Dải băng để xem các phiên bản đã tạo.

SharePoint Online: PowerShell để bật tính năng lập phiên bản

Bạn có cần bật lập phiên bản cho thư viện tài liệu trong SharePoint Online không? PowerShell có thể giúp ích! Đây là PowerShell để bật lịch sử phiên bản trên một danh sách hoặc thư viện nhất định:


#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"

Function Enable-SPOVersioning()
{
    param
    (
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ListName
    )
    Try {
        #Setup Credentials to connect
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
         
        #Get the List
        $List = $Ctx.Web.Lists.GetByTitle($ListName)
        
        #sharepoint online powershell enable versioning
        $List.EnableVersioning = $True
        $List.MajorVersionLimit = 50
        $List.Update()
        $Ctx.ExecuteQuery() 
        Write-host -f Green "Versioning has been turned ON at $ListName"
 
    }
    Catch {
        write-host -f Red "Error:" $_.Exception.Message
    }
}

#Set Parameters
$SiteURL="https://Crescent.sharepoint.com"
$ListName="Projects"

#Call the function 
Enable-SPOVersioning -SiteURL $SiteURL -ListName $ListName

Tập lệnh PowerShell để bật lập phiên bản trên tất cả danh sách và thư viện trong SharePoint Online:

Nếu bạn giống tôi, bạn luôn tìm cách tự động hóa các công việc và tiết kiệm thời gian. Với ý nghĩ đó, tôi muốn chia sẻ mẹo nhanh về cách bật lập phiên bản cho tất cả danh sách và thư viện trong trang SharePoint Online bằng PowerShell. Hãy kích hoạt lịch sử phiên bản trên tất cả các danh sách và thư viện của trang SharePoint Online:


#Load SharePoint Online 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"
   
##Variables for Processing
$SiteUrl = "https://portal.crescent.com.com/sites/Sales/"
$UserName="Salaudeen@crescent.com"
$Password ="Password goes here"

try{  
    #Setup the context
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
    $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
    $Context.Credentials = $credentials
    
    #get the site and lists
    $web = $context.Web
    $context.Load($web)
    $context.load($web.lists)
    $Context.executeQuery() 
 
    #Iterate through each list in the web
    foreach($list in $web.lists){
    if ($list.hidden -eq $false)
    {
        #Enable versioning
        $list.EnableVersioning = $true
        $lIST.MajorVersionLimit = 50
        $list.Update()
        $Context.ExecuteQuery() 
        Write-host "Versioning has been turned ON at :"$List.title
    }
  }
}
catch{
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
} 

Tập lệnh này bật tính năng lập phiên bản trong SharePoint Online cho tất cả các danh sách và thư viện trên trang đã cho. Nếu bạn muốn lọc và bật tính năng lập phiên bản trên các thư viện tài liệu, hãy sử dụng cách sau:


If($List.BaseType -eq "DocumentLibrary")
{
   #Enable version history
}

SharePoint Online: Bật lập phiên bản bằng PnP PowerShell

Để kiểm tra xem tính năng lập phiên bản có được bật cho Danh sách hay không, hãy sử dụng: $List.EnableVersioning


#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$ListName ="Projects"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get List
$List = Get-PnPList $ListName 

If($List)
{ 
    #sharepoint online enable versioning powershell
    Set-PnPList -Identity $ListName -EnableVersioning $True -MajorVersions 20
}

Tương tự, bạn có thể đặt cấu hình cài đặt lập phiên bản cho tất cả danh sách trên một trang web


#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get All Lists from the web
$Lists = Get-PnPList | Where {$_.Hidden -eq $false}
ForEach($List in $Lists)
{ 
    #Enable versioning and set Number of versions to 50
    Set-PnPList -Identity $List -EnableVersioning $True -MajorVersions 50
    Write-host -f Yellow "Configured Versioning on List:"$List.Title
}

Tương tự, Để bật các phiên bản nhỏ, hãy sử dụng:


Set-PnPList -Identity $ListName -EnableVersioning $True -EnableMinorVersions $True -MajorVersions 25 -MinorVersions 25

Bật lập phiên bản với các phiên bản chính và phụ cho tất cả thư viện tài liệu trong một trang web

Đây là PnP PowerShell để kích hoạt các phiên bản nhỏ cho tất cả các thư viện:


#Config Variables
$SiteURL = "https://crescent.sharepoint.com/sites/Neo"
 
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

#Get all document libraries
$Libraries =  Get-PnPList | Where {$_.BaseType -eq "DocumentLibrary" -and $_.Hidden -eq $False}

ForEach($Library in $Libraries)
{ 
    #sharepoint online enable versioning powershell
    Set-PnPList -Identity $Library -EnableVersioning $True -EnableMinorVersions $True
}

Làm cách nào để đặt cấu hình lịch sử phiên bản trên tất cả các thư viện tài liệu cho toàn bộ tuyển tập trang?


#Config Variables
$SiteURL = "https://crescent.sharepoint.com/Sites/Retail"

#Exclude certain libraries
$ExcludedLists = ("Preservation Hold Library","Site Assets","Site Pages","Style Library","Form Templates")

Function Enable-PnPVersionHistory($SiteURL)
{
    
    Write-host "Processing Web $($_.URL)" -f Cyan
    Connect-PnPOnline -Url $SiteURL -Interactive

    #Get All Document Libraries
    $Lists = Get-PnPList | Where-Object {$_.Hidden -eq $False -and $_.BaseType -eq "DocumentLibrary" -and $ExcludedLists -notcontains $_.Title}

    #Enable Version History for Document Libraries
        $Lists | ForEach-Object {
        $Params = @{
            "Identity"         = $_.Title
            "EnableVersioning" = $True
            "MajorVersions"    = 50
            "MinorVersions"    = 10
        }
        #Set-PnPList @Params
        Write-host "Enabled Version History for "$_.Title -f Green
    }
    
}

#Connect to SharePoint Online Site from PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

#Get all Webs and call the function to set version history
Get-PnPSubWeb -IncludeRootWeb | ForEach-Object { Enable-PnPVersionHistory $_.URL }
SharePoint Online lưu giữ lịch sử phiên bản trong bao lâu? Mãi mãi!

Bài viết liên quan