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.

SharePoint Online Enable Document ID Service using PowerShell

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 
Tips: You can use the above PowerShell script to reset document ID prefix! Once you set the document ID prefix with PowerShell, make sure you go to: Site settings >> Document ID settings >> Choose “Reset all Document IDs in this Site Collection to begin with these characters” manually!

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.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

5 thoughts on “SharePoint Online: Enable Document ID Service using PowerShell

  • 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!”
    }

    Reply
  • 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?

    Reply
    • 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.

      Reply
  • Do you know the property for the checkbox of reset document id in sharepoint site collection like docid_enabled?

    Reply
    • 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.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *