diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f66d54a0..e0009c99b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +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) - Added `-Force` option to `Set-PnPListem` to force it to update a list item even without changing something. Can be useful in i.e. triggering a webhook. [#2396](https://github.com/pnp/powershell/pull/2396) - Added `ImageUrl`, `PageImageAlignment`, `ImageHeight` and `ImageWidth` parameters to `Add-PnPPageTextPart` cmdlet so that users can add an inline image into a text webpart. [#2401](https://github.com/pnp/powershell/pull/2401) diff --git a/documentation/Set-PnPList.md b/documentation/Set-PnPList.md index 8451852ec..66276b6aa 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. I.e. lists\newname. + +```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..faf6ff1e3 100644 --- a/src/Commands/Lists/SetList.cs +++ b/src/Commands/Lists/SetList.cs @@ -1,6 +1,8 @@ using Microsoft.SharePoint.Client; + using PnP.PowerShell.Commands.Base.PipeBinds; using PnP.PowerShell.Commands.Enums; + using System.Management.Automation; namespace PnP.PowerShell.Commands.Lists @@ -81,177 +83,192 @@ 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); + WriteWarning($"List {Identity} not found"); + return; + } - var enableVersioning = list.EnableVersioning; - var enableMinorVersions = list.EnableMinorVersions; - var enableAttachments = list.EnableAttachments; - var updateRequired = false; - if (BreakRoleInheritance) - { - list.BreakRoleInheritance(CopyRoleAssignments, ClearSubscopes); - updateRequired = true; - } + if (ParameterSpecified(nameof(Path))) + { + // Move the list to its newly requested location within the same site + list.RootFolder.MoveTo(Path); + ClientContext.ExecuteQueryRetry(); - if (list.HasUniqueRoleAssignments && ResetRoleInheritance) - { - list.ResetRoleInheritance(); - updateRequired = true; - } + // 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); + } - if (!string.IsNullOrEmpty(Title)) - { - list.Title = Title; - 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 (ParameterSpecified(nameof(Hidden)) && Hidden != list.Hidden) - { - list.Hidden = Hidden; - 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 (ParameterSpecified(nameof(EnableContentTypes)) && list.ContentTypesEnabled != EnableContentTypes) - { - list.ContentTypesEnabled = EnableContentTypes; - updateRequired = true; - } + if (list.HasUniqueRoleAssignments && ResetRoleInheritance) + { + list.ResetRoleInheritance(); + updateRequired = true; + } - if (ParameterSpecified(nameof(EnableVersioning)) && EnableVersioning != enableVersioning) - { - list.EnableVersioning = EnableVersioning; - updateRequired = true; - } + if (!string.IsNullOrEmpty(Title)) + { + list.Title = Title; + updateRequired = true; + } - if (ParameterSpecified(nameof(EnableMinorVersions)) && EnableMinorVersions != enableMinorVersions) - { - list.EnableMinorVersions = EnableMinorVersions; - updateRequired = true; - } + if (ParameterSpecified(nameof(Hidden)) && Hidden != list.Hidden) + { + list.Hidden = Hidden; + updateRequired = true; + } - if (ParameterSpecified(nameof(EnableModeration)) && list.EnableModeration != EnableModeration) - { - list.EnableModeration = EnableModeration; - updateRequired = true; - } + if (ParameterSpecified(nameof(EnableContentTypes)) && list.ContentTypesEnabled != EnableContentTypes) + { + list.ContentTypesEnabled = EnableContentTypes; + updateRequired = true; + } - if (ParameterSpecified(nameof(DraftVersionVisibility))) - { - list.DraftVersionVisibility = DraftVersionVisibility; - updateRequired = true; - } + if (ParameterSpecified(nameof(EnableVersioning)) && EnableVersioning != enableVersioning) + { + list.EnableVersioning = EnableVersioning; + updateRequired = true; + } - if (ParameterSpecified(nameof(EnableAttachments)) && EnableAttachments != enableAttachments) - { - list.EnableAttachments = EnableAttachments; - updateRequired = true; - } + if (ParameterSpecified(nameof(EnableMinorVersions)) && EnableMinorVersions != enableMinorVersions) + { + list.EnableMinorVersions = EnableMinorVersions; + updateRequired = true; + } - if (ParameterSpecified(nameof(Description))) - { - list.Description = Description; - updateRequired = true; - } + if (ParameterSpecified(nameof(EnableModeration)) && list.EnableModeration != EnableModeration) + { + list.EnableModeration = EnableModeration; + updateRequired = true; + } - if (ParameterSpecified(nameof(EnableFolderCreation))) - { - list.EnableFolderCreation = EnableFolderCreation; - updateRequired = true; - } + if (ParameterSpecified(nameof(DraftVersionVisibility))) + { + list.DraftVersionVisibility = DraftVersionVisibility; + updateRequired = true; + } - if (ParameterSpecified(nameof(ForceCheckout))) - { - list.ForceCheckout = ForceCheckout; - updateRequired = true; - } + if (ParameterSpecified(nameof(EnableAttachments)) && EnableAttachments != enableAttachments) + { + list.EnableAttachments = EnableAttachments; + updateRequired = true; + } - if (ParameterSpecified(nameof(ListExperience))) - { - list.ListExperienceOptions = ListExperience; - updateRequired = true; - } + if (ParameterSpecified(nameof(Description))) + { + list.Description = Description; + updateRequired = true; + } - if (ParameterSpecified(nameof(ReadSecurity))) - { - list.ReadSecurity = (int)ReadSecurity; - updateRequired = true; - } + if (ParameterSpecified(nameof(EnableFolderCreation))) + { + list.EnableFolderCreation = EnableFolderCreation; + updateRequired = true; + } - if (ParameterSpecified(nameof(WriteSecurity))) - { - list.WriteSecurity = (int)WriteSecurity; - updateRequired = true; - } + if (ParameterSpecified(nameof(ForceCheckout))) + { + list.ForceCheckout = ForceCheckout; + updateRequired = true; + } - if (ParameterSpecified(nameof(NoCrawl))) - { - list.NoCrawl = NoCrawl; - updateRequired = true; - } + if (ParameterSpecified(nameof(ListExperience))) + { + list.ListExperienceOptions = ListExperience; + updateRequired = true; + } - if (ParameterSpecified(nameof(ExemptFromBlockDownloadOfNonViewableFiles))) - { - list.SetExemptFromBlockDownloadOfNonViewableFiles(ExemptFromBlockDownloadOfNonViewableFiles); - updateRequired = true; - } + if (ParameterSpecified(nameof(ReadSecurity))) + { + list.ReadSecurity = (int)ReadSecurity; + updateRequired = true; + } - if (ParameterSpecified(nameof(DisableGridEditing))) - { - list.DisableGridEditing = DisableGridEditing; - updateRequired = true; - } + if (ParameterSpecified(nameof(WriteSecurity))) + { + list.WriteSecurity = (int)WriteSecurity; + updateRequired = true; + } - if (updateRequired) - { - list.Update(); - ClientContext.ExecuteQueryRetry(); - } - updateRequired = false; + if (ParameterSpecified(nameof(NoCrawl))) + { + list.NoCrawl = NoCrawl; + updateRequired = true; + } - if (list.EnableVersioning) - { - // list or doclib? + if (ParameterSpecified(nameof(ExemptFromBlockDownloadOfNonViewableFiles))) + { + list.SetExemptFromBlockDownloadOfNonViewableFiles(ExemptFromBlockDownloadOfNonViewableFiles); + updateRequired = true; + } - if (list.BaseType == BaseType.DocumentLibrary) - { + if (ParameterSpecified(nameof(DisableGridEditing))) + { + list.DisableGridEditing = DisableGridEditing; + updateRequired = true; + } - if (ParameterSpecified(nameof(MajorVersions))) - { - list.MajorVersionLimit = (int)MajorVersions; - updateRequired = true; - } - - if (ParameterSpecified(nameof(MinorVersions)) && list.EnableMinorVersions) - { - list.MajorWithMinorVersionsLimit = (int)MinorVersions; - updateRequired = true; - } - } - else + if (updateRequired) + { + list.Update(); + ClientContext.ExecuteQueryRetry(); + } + + updateRequired = false; + + 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); } } -} +} \ No newline at end of file