SharePoint Online:使用 PowerShell 启用文档 ID 服务
文档ID服务功能自动为上传的文档分配唯一的ID,有助于高效跟踪和管理文档。我的另一篇文章“如何在 SharePoint Online 中配置文档 ID 服务功能?”中解释了配置文档 ID 服务。
可以使用 PowerShell 启用文档 ID 服务,这提供了管理 SharePoint Online 配置的便捷且自动化的方法。在本文中,我们将逐步介绍使用 PowerShell 在 SharePoint Online 中启用文档 ID 服务的过程,并提供分步指南。
让我们看看如何使用 PowerShell 启用文档 ID 服务:
步骤 1:激活 SharePoint Online 中的文档 ID 功能
作为启用文档 ID 的第一步,我们需要激活网站集中的一项功能。
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Sales"
$FeatureId = "b50e3104-6812-424f-a011-cc90e6327318"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#Get the Feature
$Feature = Get-PnPFeature -Scope Site -Identity $FeatureId
#Get the Feature status
If($Feature.DefinitionId -eq $null)
{
#enable document id feature in sharepoint online using powershell
Write-host -f Yellow "Activating Document ID Service Feature..."
Enable-PnPFeature -Scope Site -Identity $FeatureId -Force
Write-host -f Green "Document ID Service Feature Activated Successfully!"
}
Else
{
Write-host -f Yellow "Document ID Service Feature is already active!"
}
步骤 2:配置 SharePoint Online 文档 ID 设置
启用该功能后,我们需要在网站集级别对其进行配置。在配置文档 ID 设置之前,必须为 SharePoint Online 网站集启用自定义脚本。
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Sales"
$DocIDPrefix = "Sales"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#Configure the Document ID properties
Set-PnPPropertyBagValue -Key "docid_enabled" -Value "1"
Set-PnPPropertyBagValue -Key "docid_msft_hier_siteprefix" -Value $DocIDPrefix
提示:您可以使用上面的PowerShell脚本来重置文档ID前缀!使用 PowerShell 设置文档 ID 前缀后,请确保转到:网站设置 >> 文档 ID 设置 >> 手动选择“重置此网站集中的所有文档 ID 以这些字符开头”!
步骤 3:将文档 ID 列添加到 SharePoint Online
等待一段时间,然后查看从指定配置填充的文档 ID 列。如果需要,您可以将该列添加到文档库的默认视图中。
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Sales"
$LibraryName = "Team Documents"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#Get the Default View from the list
$DefaultListView = Get-PnPView -List $LibraryName | Where {$_.DefaultView -eq $True}
#Add column to the View
If($DefaultListView.ViewFields -notcontains "_dlc_DocIdUrl")
{
$DefaultListView.ViewFields.Add("_dlc_DocIdUrl")
$DefaultListView.Update()
Invoke-PnPQuery
Write-host -f Green "Document ID column Added to the Default View!"
}
else
{
Write-host -f Yellow "Document ID column already exists in the list!"
}
结论
在 SharePoint Online 中启用文档 ID 服务是改进组织中内容的管理和跟踪的有效方法。通过为文档分配唯一的标识号,可以更轻松地查找、访问和共享内容,从而降低数据丢失的风险并确保正确组织和跟踪您的内容。使用 PowerShell 启用此服务提供了一种方便且自动化的方式来管理 SharePoint Online 环境,使其能够快速轻松地设置和配置。通过执行本文中概述的步骤,您可以改进内容管理并利用 SharePoint Online 中文档 ID 服务的强大功能和优势。
