Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added optional -IncludeAllLists to Get-PnPSiteScriptFromWeb #1987

Merged
merged 4 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [#1987](https://github.com/pnp/powershell/pull/1987)
- Added `-UpdateChildren` parameter to `Add-PnPFieldToContentType` cmdlet. This allows users to skip pushing the fields to child content types. [#1092](https://github.com/pnp/powershell/pull/1992)

### Changed
Expand Down
75 changes: 44 additions & 31 deletions documentation/Get-PnPSiteScriptFromWeb.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,57 +32,57 @@ Get-PnPSiteScriptFromWeb [-Url <String>] [-Lists <String[]>] [-IncludeBranding]
[-Connection <PnPConnection>] [<CommonParameters>]
```

### All lists
```powershell
Get-PnPSiteScriptFromWeb [-Url <String>] [-IncludeAllLists] [-IncludeBranding] [-IncludeLinksToExportedItems]
[-IncludeRegionalSettings] [-IncludeSiteExternalSharingCapability] [-IncludeTheme]
[-Connection <PnPConnection>] [<CommonParameters>]
```

## 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.

## EXAMPLES

### 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
Expand All @@ -100,7 +100,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
Expand All @@ -114,7 +114,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
Expand All @@ -128,7 +128,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
Expand All @@ -142,7 +142,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
Expand All @@ -156,7 +156,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
Expand All @@ -166,11 +180,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
Expand All @@ -193,13 +207,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
Expand Down
26 changes: 22 additions & 4 deletions src/Commands/SiteDesigns/GetSiteScriptFromWeb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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,
Expand Down