From b51236296e0bff1a54bbf420fa86a55cbf7f44cd Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Wed, 4 Sep 2024 17:24:04 +0200 Subject: [PATCH 1/3] Implementation added --- CHANGELOG.md | 1 + documentation/Reset-PnPDocumentId.md | 60 +++++++++++++++++++++++++++ src/Commands/Files/ResetDocumentId.cs | 29 +++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 documentation/Reset-PnPDocumentId.md create mode 100644 src/Commands/Files/ResetDocumentId.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 44541f265..564f936b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added `-SkipCertCreation` parameter in `Register-PnPAzureADApp` cmdlet to prevent creation and uploading of certificates in the Entra ID app. - Added support to `-ValidateConnection` in managed identity authentication. - Added `OverrideSharingCapability`, `RequestFilesLinkExpirationInDays` & `RequestFilesLinkEnabled` parameters to `Set-PnPTenantSite` cmdlet. +- Added `Reset-PnPDocumentID` cmdlet to request resetting the document ID for a document ### Changed diff --git a/documentation/Reset-PnPDocumentId.md b/documentation/Reset-PnPDocumentId.md new file mode 100644 index 000000000..cb1ac8233 --- /dev/null +++ b/documentation/Reset-PnPDocumentId.md @@ -0,0 +1,60 @@ +--- +Module Name: PnP.PowerShell +title: Reset-PnPDocumentId +schema: 2.0.0 +applicable: SharePoint Online +external help file: PnP.PowerShell.dll-Help.xml +online version: https://pnp.github.io/powershell/cmdlets/Reset-PnPDocumentId.html +--- + +# Reset-PnPDocumentId + +## SYNOPSIS +Requests the unique document ID of a file to be recalculated and reassigned. + +## SYNTAX + +```powershell +Reset-PnPDocumentId -Identity [-Verbose] [-Connection ] +``` + +## DESCRIPTION +This cmdlet allows requesting SharePoint Online to recalculate and reassign the unique document ID of a file. This can be useful if the document ID of a file has been lost, has gotten corrupted or duplicated. The unique document ID will be calculated based on an internal predictable algorithm and will contain parts of the site collection, web, list and listitem. It should only take seconds for it to recalculate and reassign the document ID. If it remains the same after running this cmdlet, it means the assigned document ID is correct. There's no use of running it multiple times on the same file. + +You need to be connected to the same site collection in which the file on which you wish to perform the operation resides. + +## EXAMPLES + +### EXAMPLE 1 +```powershell +Reset-PnPDocumentId -Identity "/sites/demo/Shared Documents/MyDocument.docx" +``` + +This will request SharePoint Online to recalculate and reassign the unique document ID of the file MyDocument.docx in the Shared Documents library of the demo site collection. + +### EXAMPLE 2 +```powershell +Get-PnPFileInFolder -Recurse -FolderSiteRelativeUrl "Shared Documents" -ItemName "MyDocument.docx" | Reset-PnPDocumentId +``` + +This will request SharePoint Online to recalculate and reassign the unique document ID of the file MyDocument.docx in the Shared Documents library of the current site collection. + +## PARAMETERS + +### -Identity +The ID, listitem instance, File instance or server relative path of the file for which you want to request a document id reset. + +```yaml +Type: FilePipeBind +Parameter Sets: (All) + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## RELATED LINKS + +[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) \ No newline at end of file diff --git a/src/Commands/Files/ResetDocumentId.cs b/src/Commands/Files/ResetDocumentId.cs new file mode 100644 index 000000000..ffb1e0961 --- /dev/null +++ b/src/Commands/Files/ResetDocumentId.cs @@ -0,0 +1,29 @@ +using System; +using System.Management.Automation; +using Microsoft.SharePoint.Client; +using PnP.PowerShell.Commands.Base.PipeBinds; +using PnP.PowerShell.Commands.Utilities.REST; + +namespace PnP.PowerShell.Commands.Files +{ + [Cmdlet(VerbsCommon.Reset, "PnPDocumentId")] + public class ResetDocumentId : PnPWebCmdlet + { + [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)] + public FilePipeBind Identity; + + protected override void ExecuteCmdlet() + { + var file = Identity.GetFile(ClientContext, this); + file.EnsureProperties(f => f.ServerRelativeUrl); + CurrentWeb.EnsureProperty(w => w.Url); + + // Even though the URL parameter states server relative path, it requires the site relative path of the file + var siteRelativeUrl = file.ServerRelativeUrl.Remove(0, new Uri(CurrentWeb.Url).AbsolutePath.Length); + var url = $"{CurrentWeb.Url}/_api/SP.DocumentManagement.DocumentId/ResetDocIdByServerRelativePath(decodedUrl='{siteRelativeUrl}')"; + + WriteVerbose($"Making a POST request to {url} to request a new document ID for the file {file.ServerRelativeUrl}"); + RestHelper.Post(Connection.HttpClient, url, ClientContext); + } + } +} From bbcd6915b9064ab1e2b1c63ba2803841f1e1bfb2 Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Wed, 4 Sep 2024 17:25:18 +0200 Subject: [PATCH 2/3] Added PR reference --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 564f936b3..9328aa311 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added `-SkipCertCreation` parameter in `Register-PnPAzureADApp` cmdlet to prevent creation and uploading of certificates in the Entra ID app. - Added support to `-ValidateConnection` in managed identity authentication. - Added `OverrideSharingCapability`, `RequestFilesLinkExpirationInDays` & `RequestFilesLinkEnabled` parameters to `Set-PnPTenantSite` cmdlet. -- Added `Reset-PnPDocumentID` cmdlet to request resetting the document ID for a document +- Added `Reset-PnPDocumentID` cmdlet to request resetting the document ID for a document [#4238](https://github.com/pnp/powershell/pull/4238) ### Changed From 51fe7e8e732a1774849964bffacbba71b162d84f Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Tue, 10 Sep 2024 13:59:30 +0200 Subject: [PATCH 3/3] Moving changelog entry to nightly section --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a90286433..7734ecb07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Added +- Added `Reset-PnPDocumentID` cmdlet to request resetting the document ID for a document [#4238](https://github.com/pnp/powershell/pull/4238) + ### Changed ### Fixed @@ -29,7 +31,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added `New-PnPSearchExternalConnection`, `Get-PnPSearchExternalConnection`, `Set-PnPSearchExternalConnection` and `Remove-PnPSearchExternalConnection` cmdlets to manage external connections for Microsoft Search [#4231](https://github.com/pnp/powershell/pull/4231) - Added `Get-PnPSearchExternalSchema` and `Set-PnPSearchExternalSchema` cmdlets to manage the schema for external connections for Microsoft Search [#4231](https://github.com/pnp/powershell/pull/4231) - Added `OverrideSharingCapability`, `RequestFilesLinkExpirationInDays` & `RequestFilesLinkEnabled` parameters to `Set-PnPTenantSite` cmdlet. -- Added `Reset-PnPDocumentID` cmdlet to request resetting the document ID for a document [#4238](https://github.com/pnp/powershell/pull/4238) ### Changed