How to Get or Set SharePoint Document ID _dlc_DocId using PowerShell


Posted on : Fri, 18th Sep 15 09:45 am (Updated on : Fri, 18th Sep 15 09:45 am) UTC
Author : Code2care
100+ votes

SharePoint Document Id

Document Id is something which SharePoint internally assigns to documents and maintains a uniqueness for each document.
This Document Id never changes even if the document is moved anywhere else and so can be used as a bookmark to the document.

Just in case you want to access the DocId value or want to change it (not recommended though !!), you can refer to the the internal SharePoint column _dlc_DocId.

Get Doc Id value for a document
$item["_dlc_DocId"]

Set Doc Id value for a document
$item["_dlc_DocId"] = "NewId-12345"



Advertisements





Here is a complete example using PowerShell to access and modify the Document Id

Name : PowerShell script to get and set the Document Id (_dlc_DocId) column
  

$web = Get-SPWeb http://SharepointSiteUrl
$list = $web.lists["Shared Documents"]

//Get handle of item by ItemId
$item = $list.getitembyid(1)

//Get the Document Id using column _dlc_DocId
$item["_dlc_DocId"]

//Checkout before making changes
$item.File.CheckOut()

//Set the Document Id using column _dlc_DocId
$item["_dlc_DocId"] = "NewId-12345"
$item["_dlc_DocIdUrl"] = "http://SharePointSiteUrl/_layouts/DocIdRedir.aspx?ID=NewId-12345, NewId-12345"
$item.update()

//Check in once changes are completed
$item.File.CheckIn("DocId changed and document checked in")
  



Advertisements





Note - Once the Document Id is modified, a search crawl (incremental is sufficient) is required in order to associate the changes with the document, else you will get errors when clicking on the Document Id.

Code2care's mission is to share varied knowledge in technical and non-technical areas gathered during day-to-day learnings and development activities so that our visitors can leverage this portal to find solutions to their queries without re-inventing the wheel. Technical posts include Learnings, Tutorials, Video Tutorials, Code Snippets, Tips-n-tricks.

Follow us : Facebook - Twitter - Google +