From 0e97bfa99b651054c3e75c4776602997fd731f2d Mon Sep 17 00:00:00 2001 From: Giacomo Pozzoni Date: Wed, 3 Apr 2024 22:00:50 +0200 Subject: [PATCH] Fix Copy-PnPList handling of lookup columns Fix Copy-PnPList copying the list connected to the first lookup column instead of the specified list. --- src/Commands/Lists/CopyList.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Commands/Lists/CopyList.cs b/src/Commands/Lists/CopyList.cs index 9e0a20d98..85c0b5e95 100644 --- a/src/Commands/Lists/CopyList.cs +++ b/src/Commands/Lists/CopyList.cs @@ -2,10 +2,10 @@ using Microsoft.SharePoint.Client; using PnP.PowerShell.Commands.Base.PipeBinds; using System; -using System.Text.RegularExpressions; using System.Linq; using PnP.PowerShell.Commands.Utilities.REST; using PnP.PowerShell.Commands.Model.SharePoint; +using System.Text.Json.Nodes; namespace PnP.PowerShell.Commands.Lists { @@ -69,9 +69,15 @@ protected override void ExecuteCmdlet() if (ParameterSpecified(nameof(Title)) && !string.IsNullOrWhiteSpace(Title)) { - // Update the list name in the site script using a regular expression + // Update the list name in the site script in the first *_listName binding parameter WriteVerbose($"Setting list title to '{Title}'"); - script = Regex.Replace(script, "(?<=\"listName\":\\s?\")(.*?)(?=\")", Title); + + JsonNode scriptAsJson = JsonNode.Parse(script); + + var listNameElement = scriptAsJson["bindings"].AsObject().Where(b => b.Key.EndsWith("_listName")).First(); + listNameElement.Value["defaultValue"] = Title; + + script = scriptAsJson.ToJsonString(); } // Check if we need to set the destination to the current site