Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Commands/Lists/CopyList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down