PnP PowerShell Script to set Record Status to Locked
We needed a PnP PowerShell script to iterate over documents in a library to automatically re-label documents with our new Retention Labels.
The method SetComplianceTagWithMetaInfo is used to replace the Retention Label preserving the labelled date.
SetComplianceTagWithMetaInfo( [New Label],[isTagPolicyHold],[isTagPolicyRecord],[Labelled Date],[isEventBasedTag],[isTagSuperLock] )
We needed the method with metadata as the Retention Labels we use to mark documents as Records uses the labelled date as the start of the retention period.
SetComplianceTagWithMetaInfo, however, can only change the Retention Label when the Record status is Locked i.e. in SharePoint the document information panel will show:
As there is no PnP cmdlet to set the Record Retention Label to Locked a Graph API call is required. The GUID for the document and the Graph Drive ID of the library is required.
Firstly, a call is made to the Graph API endpoint –
https://graph.microsoft.com/v1.0/sites/[Site Address]:[Web Address]
to enumerate the Drives (Document Libraries) for the Site.
Next, we iterate over the Drives to find the Drive ID for the required Library. A Patch request can now be made to the endpoint
https://graph.microsoft.com/v1.0/drives/[Drive ID]/items/[Document GUID]/retentionLabel
with the payload
{'retentionSettings':{'isRecordLocked':'true'}}
the document is now Locked for editing and the Retention Label can be changed. See here for details.
Leave a Reply