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

[玩转系统] SharePoint Online:使用 PowerShell 配置“需要签出”选项

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

SharePoint Online:使用 PowerShell 配置“需要签出”选项


要求:在 SharePoint Online 中配置需要签出设置。

当多个用户尝试同时打开和编辑文档时,SharePoint Online 中的“要求签出”选项有助于避免保存冲突。基本上,签出是锁定文档不被其他用户编辑的快速方法。

如何在 SharePoint Online 中启用需要签出文档库?

默认情况下,“需要结账”选项处于关闭状态。我们可以打开或关闭文档库的要求签出选项。具体方法如下:

  1. 导航到您的 SharePoint Online 文档库。
  2. 单击“设置”齿轮>>选择“库设置”
  3. 在文档库设置页面上,单击版本控制设置
  4. 向下滚动到页面底部。在“需要签出”部分下,为“需要签出文档才能进行编辑?”选择“是”启用签出的选项。同样,要在 SharePoint Online 中禁用签出,请选择“否”选项。

    [玩转系统] SharePoint Online:使用 PowerShell 配置“需要签出”选项

  5. 单击“确定”保存更改。

这将打开要求签出文档库。如果您想要对 SharePoint Online 网站集中的所有文档库启用或禁用需要签出该怎么办?嗯,没有办法从 Web UI 中做到这一点。

PowerShell 设置需要在 SharePoint Online 中签出

此 PowerShell 脚本启用需要签出 SharePoint Online 中给定网站集中的所有文档库:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
Function Set-SPORequireCheckout([String] $SiteURL,[Boolean] $RequireCheckout)
{
    Try {
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
          
        #Get the web and Its subsites from given URL
        $Web = $Ctx.web
        $Ctx.Load($Web)
        $Ctx.Load($Web.Lists)
        $Ctx.Load($web.Webs)
        $Ctx.executeQuery()
  
        #Filter Document Libraries from Lists collection
        $DocumentLibraries = $Web.Lists | Where {$_.BaseType -eq "DocumentLibrary" -and $_.Hidden -eq $False}
 
        Write-host -f Yellow "Processing Site:" $SiteURL
        #Loop through each document library and set require checkout option
        Foreach ($DocumentLibrary in $DocumentLibraries)
        {
            #Require documents to be checked out before they can be edited 
            $DocumentLibrary.ForceCheckout=$RequireCheckout
            $DocumentLibrary.Update()
            $Ctx.ExecuteQuery() 
            Write-host -f Green "`t Require Checkout has been Configured for" $DocumentLibrary.Title
        }
   
        #Iterate through each subsite of the current web
        ForEach ($Subweb in $Web.Webs)
        {
            #Call the function recursively
            Set-SPORequireCheckout $Subweb.url $RequireCheckout
        }
    }
    Catch {
        write-host -f Red "Error:" $_.Exception.Message
    }
}
 
#Config Parameters
$SiteCollURL="https://Crescent.sharepoint.com"
$RequireCheckout = $True

#Setup Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Call the function to Set Require Checkout for All document libraries in the site collection
Set-SPORequireCheckout $SiteCollURL $RequireCheckout

如何在 SharePoint Online 中禁用签出?

如果已为文档库启用“需要签出”选项,我们可以使用此 PnP PowerShell 脚本为网站集中的所有库批量禁用它。


#Function to Disable Checkout Option for all libraries in a web
Function Disable-PnPRequireCheckout
{
    param
    (
        [parameter(Mandatory = $true, ValueFromPipeline = $True)]$Web
    )
      
    Try {
        Write-host "Processing Web:"$Web.URL -f Magenta
        Connect-PnPOnline -Url $Web.URL -Interactive

        #Array to exclude system libraries
        $SystemLibraries = @("Form Templates", "Pages", "Preservation Hold Library","Site Assets", "Site Pages", "Images",
                            "Site Collection Documents", "Site Collection Images","Style Library","Drop Off Library")
          
        $Libraries = Get-PnPList -Includes BaseType, Hidden, EnableVersioning -ErrorAction Stop
        #Get All document libraries
        $DocumentLibraries = $Libraries | Where {$_.BaseType -eq "DocumentLibrary" -and $_.Hidden -eq $False -and $_.Title -notin $SystemLibraries}
          
        #Disable Checkout
        ForEach($Library in $DocumentLibraries)
        {
            If($Library.ForceCheckout)
            {
                #Powershell to disable checkout for the library
                Set-PnPList -Identity $Library -ForceCheckout $false
                Write-host -f Green "`tRequire Check-out disabled on '$($Library.Title)'"
            }
            Else
            {
                Write-host -f Yellow "`tRequire Check Out is already set to 'No' at '$($Library.Title)'"
            }
        }
    }
    Catch {
        Write-host -f Red "`tError:" $_.Exception.Message
    }
}
   
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
 
#Connect to PnP Online
Connect-PnPOnline -URL $SiteURL -Interactive
 
#Call the function for each web
Get-PnPSubWeb -Recurse -IncludeRootWeb | ForEach-Object { Disable-PnPRequireCheckout $_ }

这是另一篇讨论在 SharePoint 中设置“需要签出”选项的文章:在 SharePoint 中配置“需要签出”

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

取消回复欢迎 发表评论:

关灯