From da9d1413d987b4a3bccf9307f0c58767c7564be7 Mon Sep 17 00:00:00 2001 From: James May Date: Mon, 26 Sep 2022 18:25:00 +1000 Subject: [PATCH 1/4] SetList: add "-Path" parameter for updating list URLs --- documentation/Set-PnPList.md | 24 ++- src/Commands/Lists/SetList.cs | 282 ++++++++++++++++++---------------- 2 files changed, 170 insertions(+), 136 deletions(-) diff --git a/documentation/Set-PnPList.md b/documentation/Set-PnPList.md index 8451852ec..9eb0e46e8 100644 --- a/documentation/Set-PnPList.md +++ b/documentation/Set-PnPList.md @@ -21,7 +21,8 @@ Set-PnPList -Identity [-EnableContentTypes ] [-BreakRole [-EnableAttachments ] [-EnableFolderCreation ] [-EnableVersioning ] [-EnableMinorVersions ] [-MajorVersions ] [-MinorVersions ] [-EnableModeration ] [-DraftVersionVisibility ] [-ReadSecurity ] [-WriteSecurity ] - [-NoCrawl] [-ExemptFromBlockDownloadOfNonViewableFiles ] [-DisableGridEditing ] [-Connection ] [] + [-NoCrawl] [-ExemptFromBlockDownloadOfNonViewableFiles ] [-DisableGridEditing ] + [-Path ] [-Connection ] [] ``` ## DESCRIPTION @@ -71,6 +72,13 @@ Set-PnPList -Identity "Demo List" -EnableAttachments $true Turns on attachments on a list +### EXAMPLE 7 +```powershell +Set-PnPList -Identity "Demo List" -Title "Demo List 2" -Path "Lists/DemoList2" +``` + +Rename a list, including its' URL. + ## PARAMETERS ### -BreakRoleInheritance @@ -424,6 +432,20 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Path +The new URL path of the.list. The parent folder must exist and be in the same site/web. + +```yaml +Type: String +Parameter Sets: (All) + +Required: False +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/Lists/SetList.cs b/src/Commands/Lists/SetList.cs index b877abff9..ac99295f8 100644 --- a/src/Commands/Lists/SetList.cs +++ b/src/Commands/Lists/SetList.cs @@ -1,7 +1,11 @@ using Microsoft.SharePoint.Client; + using PnP.PowerShell.Commands.Base.PipeBinds; using PnP.PowerShell.Commands.Enums; + +using System; using System.Management.Automation; +using System.Runtime; namespace PnP.PowerShell.Commands.Lists { @@ -81,177 +85,185 @@ public class SetList : PnPWebCmdlet [Parameter(Mandatory = false)] public bool DisableGridEditing; + [Parameter(Mandatory = false)] + public string Path; + protected override void ExecuteCmdlet() { var list = Identity.GetList(CurrentWeb); - if (list != null) + if (list is null) { - list.EnsureProperties(l => l.EnableAttachments, l => l.EnableVersioning, l => l.EnableMinorVersions, l => l.Hidden, l => l.EnableModeration, l => l.BaseType, l => l.HasUniqueRoleAssignments, l => l.ContentTypesEnabled, l => l.ExemptFromBlockDownloadOfNonViewableFiles, l => l.DisableGridEditing); + return; + } - var enableVersioning = list.EnableVersioning; - var enableMinorVersions = list.EnableMinorVersions; - var enableAttachments = list.EnableAttachments; - var updateRequired = false; - if (BreakRoleInheritance) - { - list.BreakRoleInheritance(CopyRoleAssignments, ClearSubscopes); - updateRequired = true; - } + list.EnsureProperties(l => l.EnableAttachments, l => l.EnableVersioning, l => l.EnableMinorVersions, l => l.Hidden, l => l.EnableModeration, l => l.BaseType, l => l.HasUniqueRoleAssignments, l => l.ContentTypesEnabled, l => l.ExemptFromBlockDownloadOfNonViewableFiles, l => l.DisableGridEditing); - if (list.HasUniqueRoleAssignments && ResetRoleInheritance) - { - list.ResetRoleInheritance(); - updateRequired = true; - } + var enableVersioning = list.EnableVersioning; + var enableMinorVersions = list.EnableMinorVersions; + var enableAttachments = list.EnableAttachments; + var updateRequired = false; + if (BreakRoleInheritance) + { + list.BreakRoleInheritance(CopyRoleAssignments, ClearSubscopes); + updateRequired = true; + } - if (!string.IsNullOrEmpty(Title)) - { - list.Title = Title; - updateRequired = true; - } + if (list.HasUniqueRoleAssignments && ResetRoleInheritance) + { + list.ResetRoleInheritance(); + updateRequired = true; + } - if (ParameterSpecified(nameof(Hidden)) && Hidden != list.Hidden) - { - list.Hidden = Hidden; - updateRequired = true; - } + if (!string.IsNullOrEmpty(Title)) + { + list.Title = Title; + updateRequired = true; + } - if (ParameterSpecified(nameof(EnableContentTypes)) && list.ContentTypesEnabled != EnableContentTypes) - { - list.ContentTypesEnabled = EnableContentTypes; - updateRequired = true; - } + if (ParameterSpecified(nameof(Hidden)) && Hidden != list.Hidden) + { + list.Hidden = Hidden; + updateRequired = true; + } - if (ParameterSpecified(nameof(EnableVersioning)) && EnableVersioning != enableVersioning) - { - list.EnableVersioning = EnableVersioning; - updateRequired = true; - } + if (ParameterSpecified(nameof(EnableContentTypes)) && list.ContentTypesEnabled != EnableContentTypes) + { + list.ContentTypesEnabled = EnableContentTypes; + updateRequired = true; + } - if (ParameterSpecified(nameof(EnableMinorVersions)) && EnableMinorVersions != enableMinorVersions) - { - list.EnableMinorVersions = EnableMinorVersions; - updateRequired = true; - } + if (ParameterSpecified(nameof(EnableVersioning)) && EnableVersioning != enableVersioning) + { + list.EnableVersioning = EnableVersioning; + updateRequired = true; + } - if (ParameterSpecified(nameof(EnableModeration)) && list.EnableModeration != EnableModeration) - { - list.EnableModeration = EnableModeration; - updateRequired = true; - } + if (ParameterSpecified(nameof(EnableMinorVersions)) && EnableMinorVersions != enableMinorVersions) + { + list.EnableMinorVersions = EnableMinorVersions; + updateRequired = true; + } - if (ParameterSpecified(nameof(DraftVersionVisibility))) - { - list.DraftVersionVisibility = DraftVersionVisibility; - updateRequired = true; - } + if (ParameterSpecified(nameof(EnableModeration)) && list.EnableModeration != EnableModeration) + { + list.EnableModeration = EnableModeration; + updateRequired = true; + } - if (ParameterSpecified(nameof(EnableAttachments)) && EnableAttachments != enableAttachments) - { - list.EnableAttachments = EnableAttachments; - updateRequired = true; - } + if (ParameterSpecified(nameof(DraftVersionVisibility))) + { + list.DraftVersionVisibility = DraftVersionVisibility; + updateRequired = true; + } - if (ParameterSpecified(nameof(Description))) - { - list.Description = Description; - updateRequired = true; - } + if (ParameterSpecified(nameof(EnableAttachments)) && EnableAttachments != enableAttachments) + { + list.EnableAttachments = EnableAttachments; + updateRequired = true; + } - if (ParameterSpecified(nameof(EnableFolderCreation))) - { - list.EnableFolderCreation = EnableFolderCreation; - updateRequired = true; - } + if (ParameterSpecified(nameof(Description))) + { + list.Description = Description; + updateRequired = true; + } - if (ParameterSpecified(nameof(ForceCheckout))) - { - list.ForceCheckout = ForceCheckout; - updateRequired = true; - } + if (ParameterSpecified(nameof(EnableFolderCreation))) + { + list.EnableFolderCreation = EnableFolderCreation; + updateRequired = true; + } - if (ParameterSpecified(nameof(ListExperience))) - { - list.ListExperienceOptions = ListExperience; - updateRequired = true; - } + if (ParameterSpecified(nameof(ForceCheckout))) + { + list.ForceCheckout = ForceCheckout; + updateRequired = true; + } - if (ParameterSpecified(nameof(ReadSecurity))) - { - list.ReadSecurity = (int)ReadSecurity; - updateRequired = true; - } + if (ParameterSpecified(nameof(ListExperience))) + { + list.ListExperienceOptions = ListExperience; + updateRequired = true; + } - if (ParameterSpecified(nameof(WriteSecurity))) - { - list.WriteSecurity = (int)WriteSecurity; - updateRequired = true; - } + if (ParameterSpecified(nameof(ReadSecurity))) + { + list.ReadSecurity = (int)ReadSecurity; + updateRequired = true; + } - if (ParameterSpecified(nameof(NoCrawl))) - { - list.NoCrawl = NoCrawl; - updateRequired = true; - } + if (ParameterSpecified(nameof(WriteSecurity))) + { + list.WriteSecurity = (int)WriteSecurity; + updateRequired = true; + } - if (ParameterSpecified(nameof(ExemptFromBlockDownloadOfNonViewableFiles))) - { - list.SetExemptFromBlockDownloadOfNonViewableFiles(ExemptFromBlockDownloadOfNonViewableFiles); - updateRequired = true; - } + if (ParameterSpecified(nameof(NoCrawl))) + { + list.NoCrawl = NoCrawl; + updateRequired = true; + } - if (ParameterSpecified(nameof(DisableGridEditing))) - { - list.DisableGridEditing = DisableGridEditing; - updateRequired = true; - } + if (ParameterSpecified(nameof(ExemptFromBlockDownloadOfNonViewableFiles))) + { + list.SetExemptFromBlockDownloadOfNonViewableFiles(ExemptFromBlockDownloadOfNonViewableFiles); + updateRequired = true; + } - if (updateRequired) - { - list.Update(); - ClientContext.ExecuteQueryRetry(); - } - updateRequired = false; + if (ParameterSpecified(nameof(DisableGridEditing))) + { + list.DisableGridEditing = DisableGridEditing; + updateRequired = true; + } - if (list.EnableVersioning) - { - // list or doclib? + if (ParameterSpecified(nameof(Path))) + { + list.RootFolder.MoveTo(Path); + updateRequired = true; + } - if (list.BaseType == BaseType.DocumentLibrary) - { + if (updateRequired) + { + list.Update(); + ClientContext.ExecuteQueryRetry(); + } + updateRequired = false; - if (ParameterSpecified(nameof(MajorVersions))) - { - list.MajorVersionLimit = (int)MajorVersions; - updateRequired = true; - } - - if (ParameterSpecified(nameof(MinorVersions)) && list.EnableMinorVersions) - { - list.MajorWithMinorVersionsLimit = (int)MinorVersions; - updateRequired = true; - } - } - else + if (list.EnableVersioning) + { + // list or doclib? + if (list.BaseType == BaseType.DocumentLibrary) + { + if (ParameterSpecified(nameof(MajorVersions))) { - if (ParameterSpecified(nameof(MajorVersions))) - { - list.MajorVersionLimit = (int)MajorVersions; - updateRequired = true; - } + list.MajorVersionLimit = (int)MajorVersions; + updateRequired = true; } - + if (ParameterSpecified(nameof(MinorVersions)) && list.EnableMinorVersions) + { + list.MajorWithMinorVersionsLimit = (int)MinorVersions; + updateRequired = true; + } } - if (updateRequired) + else { - list.Update(); - ClientContext.ExecuteQueryRetry(); + if (ParameterSpecified(nameof(MajorVersions))) + { + list.MajorVersionLimit = (int)MajorVersions; + updateRequired = true; + } } + } - WriteObject(list); + if (updateRequired) + { + list.Update(); + ClientContext.ExecuteQueryRetry(); } + + WriteObject(list); } } } From c0fdb3695c533c9604497e579b40931e9f2829db Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Fri, 30 Sep 2022 01:32:33 +0200 Subject: [PATCH 2/4] Bugfixes --- src/Commands/Lists/SetList.cs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Commands/Lists/SetList.cs b/src/Commands/Lists/SetList.cs index ac99295f8..faf6ff1e3 100644 --- a/src/Commands/Lists/SetList.cs +++ b/src/Commands/Lists/SetList.cs @@ -3,9 +3,7 @@ using PnP.PowerShell.Commands.Base.PipeBinds; using PnP.PowerShell.Commands.Enums; -using System; using System.Management.Automation; -using System.Runtime; namespace PnP.PowerShell.Commands.Lists { @@ -94,9 +92,21 @@ protected override void ExecuteCmdlet() if (list is null) { + WriteWarning($"List {Identity} not found"); return; } + if (ParameterSpecified(nameof(Path))) + { + // Move the list to its newly requested location within the same site + list.RootFolder.MoveTo(Path); + ClientContext.ExecuteQueryRetry(); + + // Fetch the list again so it will have its updated location and can be used for property updates + var newIdentity = new ListPipeBind(list.Id); + list = newIdentity.GetList(CurrentWeb); + } + list.EnsureProperties(l => l.EnableAttachments, l => l.EnableVersioning, l => l.EnableMinorVersions, l => l.Hidden, l => l.EnableModeration, l => l.BaseType, l => l.HasUniqueRoleAssignments, l => l.ContentTypesEnabled, l => l.ExemptFromBlockDownloadOfNonViewableFiles, l => l.DisableGridEditing); var enableVersioning = list.EnableVersioning; @@ -217,17 +227,12 @@ protected override void ExecuteCmdlet() updateRequired = true; } - if (ParameterSpecified(nameof(Path))) - { - list.RootFolder.MoveTo(Path); - updateRequired = true; - } - if (updateRequired) { list.Update(); ClientContext.ExecuteQueryRetry(); } + updateRequired = false; if (list.EnableVersioning) @@ -266,4 +271,4 @@ protected override void ExecuteCmdlet() WriteObject(list); } } -} +} \ No newline at end of file From d180a15e9e0cd8d27b5d21374ddddb1c8b7e0074 Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Fri, 30 Sep 2022 01:34:05 +0200 Subject: [PATCH 3/4] Minor fix --- documentation/Set-PnPList.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/Set-PnPList.md b/documentation/Set-PnPList.md index 9eb0e46e8..66276b6aa 100644 --- a/documentation/Set-PnPList.md +++ b/documentation/Set-PnPList.md @@ -433,7 +433,7 @@ Accept wildcard characters: False ``` ### -Path -The new URL path of the.list. The parent folder must exist and be in the same site/web. +The new URL path of the list. The parent folder must exist and be in the same site/web. I.e. lists\newname. ```yaml Type: String From aa22df7e634de83759784f1a4e282474c2cb2952 Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Fri, 30 Sep 2022 01:35:03 +0200 Subject: [PATCH 4/4] Added changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3be29b164..d22b2b442 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added `ScriptSafeDomainName` option to `Set-PnPSite` to allow contributors to insert iframe from specified domains only. [#2363](https://github.com/pnp/powershell/pull/2363) - Added `AlertTemplateName` paramter to `Add-PnPAlert` to allow configuring the Alert Template type name in the email. [#2362](https://github.com/pnp/powershell/pull/2362) - Added `Get-PnPAzureADActivityReportDirectoryAudit` to retrieve the audit logs generated by Azure AD. [#2095](https://github.com/pnp/powershell/pull/2095) - +- Added `-Path` option to `Set-PnPList` which allows the url of a list to be changed within the same site [#2381](https://github.com/pnp/powershell/pull/2381) ### Changed - Changed to no longer require `https://` to be prefixed when using `Connect-PnPOnline -Url tenant.sharepoint.com` [#2139](https://github.com/pnp/powershell/pull/2139)