From d0ad76a5b1faecca682717f5e2716b8e55979bfc Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 16 Jun 2022 12:51:34 +0200 Subject: [PATCH 1/3] Added optional `-IncludeAllLists` to `Get-PnPSiteScriptFromWeb` which will include the JSON definition of all custom lists of the current site in the output --- CHANGELOG.md | 1 + documentation/Get-PnPSiteScriptFromWeb.md | 68 ++++++++++--------- .../SiteDesigns/GetSiteScriptFromWeb.cs | 26 +++++-- 3 files changed, 60 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c40bfddeb..a3a82120f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added `-ExemptFromBlockDownloadOfNonViewableFiles` parameter to `Set-PnPList` cmdlet to configure access capabilites for unmanaged devices at list level. [#1973](https://github.com/pnp/powershell/pull/1973) - Added `-PercentComplete`, `-Priority`, `-StartDateTime`, `-DueDateTime` and `-Description` to `Add-PnPPlannerTask` [#1964](https://github.com/pnp/powershell/pull/1964) - Added `Set-PnPContentType` cmdlet to update the properties of the Content Types in a list or a web. [#1981](https://github.com/pnp/powershell/pull/1981) +- Added optional `-IncludeAllLists` to `Get-PnPSiteScriptFromWeb` which will include the JSON definition of all custom lists of the current site in the output ### Changed diff --git a/documentation/Get-PnPSiteScriptFromWeb.md b/documentation/Get-PnPSiteScriptFromWeb.md index 589cd4f8b..7dcb11703 100644 --- a/documentation/Get-PnPSiteScriptFromWeb.md +++ b/documentation/Get-PnPSiteScriptFromWeb.md @@ -39,50 +39,43 @@ This command allows a Site Script to be generated off of an existing site on you ### EXAMPLE 1 ```powershell +Get-PnPSiteScriptFromWeb -IncludeAll +``` + +Returns the generated Site Script JSON containing all supported components from the currently connected to site + +### EXAMPLE 2 +```powershell Get-PnPSiteScriptFromWeb -Url "https://contoso.sharepoint.com/sites/teamsite" -IncludeAll ``` Returns the generated Site Script JSON containing all supported components from the site at the provided Url -### EXAMPLE 2 +### EXAMPLE 3 ```powershell Get-PnPSiteScriptFromWeb -Url "https://contoso.sharepoint.com/sites/teamsite" -IncludeAll -Lists "Shared Documents","Lists\MyList" ``` Returns the generated Site Script JSON containing all supported components from the site at the provided Url including the lists "Shared Documents" and "MyList" -### EXAMPLE 3 +### EXAMPLE 5 ```powershell Get-PnPSiteScriptFromWeb -Url "https://contoso.sharepoint.com/sites/teamsite" -IncludeBranding -IncludeLinksToExportedItems ``` Returns the generated Site Script JSON containing the branding and navigation links from the site at the provided Url -### EXAMPLE 4 +### EXAMPLE 6 ```powershell -Get-PnPSiteScriptFromWeb -IncludeAll +Get-PnPSiteScriptFromWeb -IncludeAllLists ``` -Returns the generated Site Script JSON containing all the components from the currently connected to site +Returns the generated Site Script JSON containing all lists from the currently connected to site ## PARAMETERS -### -Connection -Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection. - -```yaml -Type: PnPConnection -Parameter Sets: (All) - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - ### -IncludeAll -If specified will include all supported components into the Site Script except for the lists and document libraries, these need to be explicitly be specified through -Lists +If specified will include all supported components into the Site Script including all self lists, branding, navigation links, regional settings, external sharing capability and theme. ```yaml Type: SwitchParameter @@ -100,7 +93,7 @@ If specified will include the branding of the site into the Site Script ```yaml Type: SwitchParameter -Parameter Sets: Specific components +Parameter Sets: Specific components, All lists Required: False Position: Named @@ -114,7 +107,7 @@ If specified will include navigation links into the Site Script ```yaml Type: SwitchParameter -Parameter Sets: Specific components +Parameter Sets: Specific components, All lists Required: False Position: Named @@ -128,7 +121,7 @@ If specified will include the regional settings into the Site Script ```yaml Type: SwitchParameter -Parameter Sets: Specific components +Parameter Sets: Specific components, All lists Required: False Position: Named @@ -142,7 +135,7 @@ If specified will include the external sharing configuration into the Site Scrip ```yaml Type: SwitchParameter -Parameter Sets: Specific components +Parameter Sets: Specific components, All lists Required: False Position: Named @@ -156,7 +149,21 @@ If specified will include the branding of the site into the Site Script ```yaml Type: SwitchParameter -Parameter Sets: Specific components +Parameter Sets: Specific components, All lists + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -IncludeAllLists +If specified, all lists that are not hidden, private, internal or catalogs will be included into the Site Script. It cannot be combined with the -Lists nor the -IncludeAll parameters as both will already include all lists. + +```yaml +Type: String[] +Parameter Sets: All lists Required: False Position: Named @@ -166,11 +173,11 @@ Accept wildcard characters: False ``` ### -Lists -Allows specifying one or more site relative URLs of lists that should be included into the Site Script, i.e. "Shared Documents","List\MyList" +Allows specifying one or more site relative URLs of lists that should be included into the Site Script, i.e. "Shared Documents","Lists\MyList" ```yaml Type: String[] -Parameter Sets: (All) +Parameter Sets: Basic components, All components, Specific components Required: False Position: Named @@ -193,13 +200,12 @@ Accept pipeline input: True (ByValue) Accept wildcard characters: False ``` -### -WhatIf -Shows what would happen if the cmdlet runs. The cmdlet is not run. +### -Connection +Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection. ```yaml -Type: SwitchParameter +Type: PnPConnection Parameter Sets: (All) -Aliases: wi Required: False Position: Named diff --git a/src/Commands/SiteDesigns/GetSiteScriptFromWeb.cs b/src/Commands/SiteDesigns/GetSiteScriptFromWeb.cs index 2027a8fd1..6c5a5a58b 100644 --- a/src/Commands/SiteDesigns/GetSiteScriptFromWeb.cs +++ b/src/Commands/SiteDesigns/GetSiteScriptFromWeb.cs @@ -11,10 +11,12 @@ public class GetSiteScriptFromWeb : PnPAdminCmdlet { private const string ParameterSet_BASICCOMPONENTS = "Basic components"; private const string ParameterSet_ALLCOMPONENTS = "All components"; + private const string ParameterSet_ALLLISTS = "All lists"; private const string ParameterSet_SPECIFICCOMPONENTS = "Specific components"; [Parameter(ParameterSetName = ParameterSet_BASICCOMPONENTS)] [Parameter(ParameterSetName = ParameterSet_ALLCOMPONENTS)] + [Parameter(ParameterSetName = ParameterSet_ALLLISTS)] [Parameter(ParameterSetName = ParameterSet_SPECIFICCOMPONENTS)] [Parameter(Mandatory = false, ValueFromPipeline = true)] public string Url; @@ -28,18 +30,26 @@ public class GetSiteScriptFromWeb : PnPAdminCmdlet [Parameter(Mandatory = false, ParameterSetName = ParameterSet_ALLCOMPONENTS)] public SwitchParameter IncludeAll; + [Parameter(Mandatory = false, ParameterSetName = ParameterSet_ALLLISTS)] + public SwitchParameter IncludeAllLists; + + [Parameter(ParameterSetName = ParameterSet_ALLLISTS)] [Parameter(Mandatory = false, ParameterSetName = ParameterSet_SPECIFICCOMPONENTS)] public SwitchParameter IncludeBranding; - + + [Parameter(ParameterSetName = ParameterSet_ALLLISTS)] [Parameter(Mandatory = false, ParameterSetName = ParameterSet_SPECIFICCOMPONENTS)] public SwitchParameter IncludeLinksToExportedItems; - + + [Parameter(ParameterSetName = ParameterSet_ALLLISTS)] [Parameter(Mandatory = false, ParameterSetName = ParameterSet_SPECIFICCOMPONENTS)] public SwitchParameter IncludeRegionalSettings; - + + [Parameter(ParameterSetName = ParameterSet_ALLLISTS)] [Parameter(Mandatory = false, ParameterSetName = ParameterSet_SPECIFICCOMPONENTS)] public SwitchParameter IncludeSiteExternalSharingCapability; + [Parameter(ParameterSetName = ParameterSet_ALLLISTS)] [Parameter(Mandatory = false, ParameterSetName = ParameterSet_SPECIFICCOMPONENTS)] public SwitchParameter IncludeTheme; @@ -48,9 +58,17 @@ protected override void ExecuteCmdlet() // If no URL specified, we take the URL of the site that the current context is connected to if(!ParameterSpecified(nameof(Url))) { - Url = PnPConnection.Current.Url; + Url = Connection.Url; } + if(IncludeAllLists || IncludeAll) + { + SiteContext.Load(SiteContext.Web.Lists, lists => lists.Where(list => !list.Hidden && !list.IsCatalog && !list.IsSystemList && !list.IsPrivate && !list.IsApplicationList && !list.IsSiteAssetsLibrary && !list.IsEnterpriseGalleryLibrary).Include(list => list.RootFolder.ServerRelativeUrl)); + SiteContext.ExecuteQueryRetry(); + + Lists = SiteContext.Web.Lists.Select(l => System.Text.RegularExpressions.Regex.Replace(l.RootFolder.ServerRelativeUrl, @"\/(?:sites|teams)\/.*?\/", string.Empty)).ToArray(); + } + var tenantSiteScriptSerializationInfo = new TenantSiteScriptSerializationInfo { IncludeBranding = IncludeBranding || IncludeAll, From 8e0b56f89e9fad5b81bb6d1d60a283260388f435 Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 16 Jun 2022 12:53:46 +0200 Subject: [PATCH 2/3] Adding to syntax --- documentation/Get-PnPSiteScriptFromWeb.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/documentation/Get-PnPSiteScriptFromWeb.md b/documentation/Get-PnPSiteScriptFromWeb.md index 7dcb11703..28d614f78 100644 --- a/documentation/Get-PnPSiteScriptFromWeb.md +++ b/documentation/Get-PnPSiteScriptFromWeb.md @@ -32,6 +32,13 @@ Get-PnPSiteScriptFromWeb [-Url ] [-Lists ] [-IncludeBranding] [-Connection ] [] ``` +### All lists +```powershell +Get-PnPSiteScriptFromWeb [-Url ] [-IncludeAllLists] [-IncludeBranding] [-IncludeLinksToExportedItems] + [-IncludeRegionalSettings] [-IncludeSiteExternalSharingCapability] [-IncludeTheme] + [-Connection ] [] +``` + ## DESCRIPTION This command allows a Site Script to be generated off of an existing site on your tenant. You need to provide at least one of the optional Include or Lists arguments. If you omit the URL, the Site Script will be created from the site to which you are connected. From 694a25721beca78e2c8602f452b7145c071c1442 Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 16 Jun 2022 13:59:31 +0200 Subject: [PATCH 3/3] Added PR reference --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3a82120f..95fec0f31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,7 +54,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added `-ExemptFromBlockDownloadOfNonViewableFiles` parameter to `Set-PnPList` cmdlet to configure access capabilites for unmanaged devices at list level. [#1973](https://github.com/pnp/powershell/pull/1973) - Added `-PercentComplete`, `-Priority`, `-StartDateTime`, `-DueDateTime` and `-Description` to `Add-PnPPlannerTask` [#1964](https://github.com/pnp/powershell/pull/1964) - Added `Set-PnPContentType` cmdlet to update the properties of the Content Types in a list or a web. [#1981](https://github.com/pnp/powershell/pull/1981) -- Added optional `-IncludeAllLists` to `Get-PnPSiteScriptFromWeb` which will include the JSON definition of all custom lists of the current site in the output +- Added optional `-IncludeAllLists` to `Get-PnPSiteScriptFromWeb` which will include the JSON definition of all custom lists of the current site in the output [#1987](https://github.com/pnp/powershell/pull/1987) ### Changed