SharePoint Online: Enable Document ID Service using PowerShell
Document ID Service feature automatically assigns a unique ID to documents uploaded, which helps to track and manage documents efficiently. Configuring document ID service is explained in my other post, How to Configure Document ID Service Feature in SharePoint Online?
The Document ID Service can be enabled using PowerShell, which provides a convenient and automated way of managing the configuration of SharePoint Online. In this article, we will walk through the process of enabling the Document ID Service in SharePoint Online using PowerShell, providing a step-by-step guide.
Let’s see how to enable the document ID service using PowerShell:
Step 1: Activate the Document ID Feature in SharePoint Online
As a first step to enable document ID, we need to activate a feature in the site collection.
#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!"
}
Step 2: Configure SharePoint Online Document ID Settings
Once the feature is enabled, we need to configure it at the site collection level. Before configuring document ID settings, you must enable custom scripting for the SharePoint Online site collection.
#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
Step 3: Add Document ID Column to SharePoint Online
Wait for some time, and see the document ID column populated from the specified configuration. If you need, you can add that column to the default view of your document libraries.
#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!"
}
Conclusion
Enabling the Document ID Service in SharePoint Online is a powerful way to improve the management and tracking of content in your organization. By assigning unique identification numbers to documents, it becomes easier to find, access, and share content, reducing the risk of data loss and ensuring that your content is properly organized and tracked. Using PowerShell to enable this service provides a convenient and automated way of managing your SharePoint Online environment, making it quick and easy to set up and configure. By following the steps outlined in this article, you can improve your content management and take advantage of the powerful features and benefits of the Document ID Service in SharePoint Online.
Hey Salaudeen,
Many thanks for this set of scripting you’ve provided.
Here is a complete script which enables the custom scripting on the site collection level and also does all the above:
#Parameters
$AdminSiteURL=”https://contoso-admin.sharepoint.com”
$SiteURL = “https://contoso.sharepoint.com/sites/Finance”
$FeatureId = “b50e3104-6812-424f-a011-cc90e6327318”
$DocIDPrefix = “CONTOSO”
$LibraryName = “Shared Documents”
#Connect to SharePoint Online Tenant Admin portal
Connect-SPOService -URL $AdminSiteURL
#Enable custom scripts to the site collection
Set-SPOSite $SiteURL -DenyAddAndCustomizePages $False
#Connect to PnP Online site
Connect-PnPOnline -Url $SiteURL -Interactive
#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!”
}
#Configure the Document ID properties
Set-PnPPropertyBagValue -Key “docid_enabled” -Value “1”
Set-PnPPropertyBagValue -Key “docid_msft_hier_siteprefix” -Value $DocIDPrefix
#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!”
}
Hello, I tried you sript. It enables the DOcumentID all right, but adding it to the default view fails it says it does not exist or has been removed by another user… And I can´t get past it. Any clues?
Although the feature is activated, It takes a while to provision the fields and other changes to document libraries. This process is completed by an automated timer job in SharePoint Online, which is out of our control! It took an hour for me. So – Wait for some time.
Do you know the property for the checkbox of reset document id in sharepoint site collection like docid_enabled?
Well, it’s not possible to reset the Document ID prefix through PowerShell in SharePoint Online (AFAIK).
Go to site settings >> Document ID settings >> Choose “Reset all Document IDs in this Site Collection to begin with these characters” manually.