Skip to content

Commit ef244c6

Browse files
Add support for applying built-in Microsoft site designs (store 1) (#5358)
The existing Get-PnPSiteDesign and Invoke-PnPSiteDesign cmdlets used CSOM (Tenant.GetSiteDesigns / Tenant.ApplySiteDesign) which only works for tenant-registered custom designs (store 0). Microsoft's built-in site designs such as Event, Department and Human Resources live in the SharePoint site template store (store 1) and require the SiteScriptUtility REST API with a store parameter — there was no way to reach them from PnP PowerShell. - Add Get-PnPSiteDesign -BuiltIn switch: calls SiteScriptUtility.GetSiteDesigns with store 1 and returns BuiltInSiteDesign objects (Id, Title, Template enum) - Add Invoke-PnPSiteDesign -Template <BuiltInSiteTemplates>: resolves the GUID from the existing BuiltInSiteTemplates enum mapping and calls SiteScriptUtility.ApplySiteDesign with store 1 - Add BuiltInSiteDesign model class for deserialising the REST response - Add GetBuiltInSiteDesigns and ApplyBuiltInSiteDesign utility methods to SiteTemplates.cs so the REST logic is centralised - Fix missing DefaultParameterSetName on Get-PnPSiteDesign to prevent ambiguous parameter set error when called without arguments - Update documentation for both cmdlets with new syntax, parameter descriptions and usage examples Co-authored-by: Gautam Sheth <gautamdsheth@outlook.com>
1 parent f6a7964 commit ef244c6

6 files changed

Lines changed: 269 additions & 54 deletions

File tree

documentation/Get-PnPSiteDesign.md

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,66 @@ online version: https://pnp.github.io/powershell/cmdlets/Get-PnPSiteDesign.html
1515

1616
* SharePoint: Access to the SharePoint Tenant Administration site
1717

18-
Retrieve Site Designs that have been registered on the current tenant.
18+
Retrieve Site Designs that have been registered on the current tenant, or list the built-in Microsoft site designs.
1919

2020
## SYNTAX
2121

22+
### Default (Default)
23+
2224
```powershell
2325
Get-PnPSiteDesign [[-Identity] <TenantSiteDesignPipeBind>] [-Connection <PnPConnection>]
2426
```
2527

28+
### BuiltIn
29+
30+
```powershell
31+
Get-PnPSiteDesign -BuiltIn [-Connection <PnPConnection>]
32+
```
33+
2634
## DESCRIPTION
2735

2836
Retrieve Site Designs that have been registered on the current tenant. When providing a name with -Identity, it returns all site designs with that name.
2937

38+
Use the -BuiltIn switch to instead return the built-in Microsoft site designs (e.g. Event, Department, Human Resources) which are available from the SharePoint site template store.
39+
3040
## EXAMPLES
3141

3242
### EXAMPLE 1
3343
```powershell
3444
Get-PnPSiteDesign
3545
```
3646

37-
Returns all registered site designs
47+
Returns all tenant-registered site designs.
3848

3949
### EXAMPLE 2
4050
```powershell
4151
Get-PnPSiteDesign -Identity 5c73382d-9643-4aa0-9160-d0cba35e40fd
4252
```
4353

44-
Returns a specific registered site designs
54+
Returns a specific registered site design.
55+
56+
### EXAMPLE 3
57+
```powershell
58+
Get-PnPSiteDesign -BuiltIn
59+
```
60+
61+
Returns all built-in Microsoft site designs, including their Ids, titles, and matching template enum values.
62+
63+
### EXAMPLE 4
64+
```powershell
65+
Get-PnPSiteDesign -BuiltIn | Where-Object { $_.Template -eq "Event" }
66+
```
67+
68+
Returns the built-in Event site design.
4569

4670
## PARAMETERS
4771

4872
### -Identity
49-
If specified will retrieve the specified site design
73+
If specified, retrieves the site design with the given Id or name.
5074

5175
```yaml
5276
Type: TenantSiteDesignPipeBind
53-
Parameter Sets: (All)
77+
Parameter Sets: Default
5478

5579
Required: False
5680
Position: 0
@@ -59,6 +83,20 @@ Accept pipeline input: True (ByValue)
5983
Accept wildcard characters: False
6084
```
6185
86+
### -BuiltIn
87+
When specified, returns the built-in Microsoft site designs from the SharePoint site template store (store 1) instead of tenant-registered designs.
88+
89+
```yaml
90+
Type: SwitchParameter
91+
Parameter Sets: BuiltIn
92+
93+
Required: True
94+
Position: Named
95+
Default value: None
96+
Accept pipeline input: False
97+
Accept wildcard characters: False
98+
```
99+
62100
### -Connection
63101
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.
64102
@@ -75,4 +113,4 @@ Accept wildcard characters: False
75113
76114
## RELATED LINKS
77115
78-
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
116+
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)

documentation/Invoke-PnPSiteDesign.md

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,27 @@ Apply a Site Design to an existing site. * Requires Tenant Administration Rights
1414

1515
## SYNTAX
1616

17+
### By Site Design (Default)
18+
1719
```powershell
1820
Invoke-PnPSiteDesign [-Identity] <TenantSiteDesignPipeBind> [-WebUrl <String>]
1921
[-Connection <PnPConnection>]
2022
```
2123

24+
### By Built-in Template
25+
26+
```powershell
27+
Invoke-PnPSiteDesign -Template <BuiltInSiteTemplates> [-WebUrl <String>]
28+
[-Connection <PnPConnection>]
29+
```
30+
2231
## DESCRIPTION
2332

24-
Applies the Site Design provided through Identity to an existing site. When providing a site design name and multiple site designs exist with the same name, all of them will be invoked.
33+
Applies a Site Design to an existing site.
34+
35+
Use `-Identity` to apply a tenant-registered site design by Id or name. When a name matches multiple designs, all of them will be invoked.
36+
37+
Use `-Template` to apply one of the built-in Microsoft site designs (e.g. Event, Department, Human Resources) directly by name, without needing to look up the design Id first. This calls the SharePoint SiteScriptUtility REST API against the built-in template store (store 1).
2538

2639
## EXAMPLES
2740

@@ -44,30 +57,30 @@ Applies the specified site design to the specified site.
4457
Get-PnPSiteDesign | ?{$_.Title -eq "Demo"} | Invoke-PnPSiteDesign
4558
```
4659

47-
Applies the specified site design to the specified site.
48-
49-
## PARAMETERS
60+
Applies the site design named "Demo" to the current site via the pipeline.
5061

51-
### -Connection
52-
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.
62+
### EXAMPLE 4
63+
```powershell
64+
Invoke-PnPSiteDesign -Template Event -WebUrl "https://contoso.sharepoint.com/sites/myevent"
65+
```
5366

54-
```yaml
55-
Type: PnPConnection
56-
Parameter Sets: (All)
67+
Applies the built-in Event site design to the specified communication site.
5768

58-
Required: False
59-
Position: Named
60-
Default value: None
61-
Accept pipeline input: False
62-
Accept wildcard characters: False
69+
### EXAMPLE 5
70+
```powershell
71+
Invoke-PnPSiteDesign -Template Department
6372
```
6473

74+
Applies the built-in Department site design to the current site.
75+
76+
## PARAMETERS
77+
6578
### -Identity
66-
The Site Design Id or an actual Site Design object to apply
79+
The Site Design Id, name, or an actual Site Design object to apply.
6780

6881
```yaml
6982
Type: TenantSiteDesignPipeBind
70-
Parameter Sets: (All)
83+
Parameter Sets: By Site Design
7184

7285
Required: True
7386
Position: 0
@@ -76,7 +89,19 @@ Accept pipeline input: True (ByValue)
7689
Accept wildcard characters: False
7790
```
7891
92+
### -Template
93+
The name of a built-in Microsoft site design to apply. Uses the SharePoint SiteScriptUtility REST API against the built-in template store (store 1). Cannot be combined with -Identity.
7994
95+
```yaml
96+
Type: BuiltInSiteTemplates
97+
Parameter Sets: By Built-in Template
98+
99+
Required: True
100+
Position: Named
101+
Default value: None
102+
Accept pipeline input: False
103+
Accept wildcard characters: False
104+
```
80105
81106
### -WebUrl
82107
The URL of the web to apply the site design to. If not specified it will default to the current web based upon the URL specified with Connect-PnPOnline.
@@ -92,7 +117,20 @@ Accept pipeline input: False
92117
Accept wildcard characters: False
93118
```
94119
120+
### -Connection
121+
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.
122+
123+
```yaml
124+
Type: PnPConnection
125+
Parameter Sets: (All)
126+
127+
Required: False
128+
Position: Named
129+
Default value: None
130+
Accept pipeline input: False
131+
Accept wildcard characters: False
132+
```
133+
95134
## RELATED LINKS
96135
97136
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
98-
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Text.Json.Serialization;
3+
using PnP.PowerShell.Commands.Enums;
4+
using PnP.PowerShell.Commands.Model.SharePoint;
5+
6+
namespace PnP.PowerShell.Commands.Model.SharePoint
7+
{
8+
/// <summary>
9+
/// Represents a built-in Microsoft SharePoint site design returned from the SiteScriptUtility REST API (store 1)
10+
/// </summary>
11+
public class BuiltInSiteDesign
12+
{
13+
[JsonPropertyName("Id")]
14+
public Guid Id { get; set; }
15+
16+
[JsonPropertyName("Title")]
17+
public string Title { get; set; }
18+
19+
/// <summary>
20+
/// Maps the Id back to the known BuiltInSiteTemplates enum value, if recognised
21+
/// </summary>
22+
public BuiltInSiteTemplates? Template
23+
{
24+
get
25+
{
26+
if (BuiltInSiteTemplateSettings.BuiltInSiteTemplateMappings.TryGetValue(Id, out var template))
27+
return template;
28+
return null;
29+
}
30+
}
31+
}
32+
}

src/Commands/SiteDesigns/GetSiteDesign.cs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,52 @@
1-
using Microsoft.Online.SharePoint.TenantAdministration;
1+
using Microsoft.Online.SharePoint.TenantAdministration;
22
using Microsoft.SharePoint.Client;
33
using PnP.PowerShell.Commands.Base;
44
using PnP.PowerShell.Commands.Base.PipeBinds;
5+
using PnP.PowerShell.Commands.Model.SharePoint;
6+
using PnP.PowerShell.Commands.Utilities;
7+
using System.Collections.Generic;
58
using System.Linq;
69
using System.Management.Automation;
710

811
namespace PnP.PowerShell.Commands
912
{
10-
[Cmdlet(VerbsCommon.Get, "PnPSiteDesign")]
13+
[Cmdlet(VerbsCommon.Get, "PnPSiteDesign", DefaultParameterSetName = "Default")]
14+
[OutputType(typeof(TenantSiteDesign), ParameterSetName = new[] { "Default" })]
15+
[OutputType(typeof(IEnumerable<BuiltInSiteDesign>), ParameterSetName = new[] { "BuiltIn" })]
1116
public class GetSiteDesign : PnPSharePointOnlineAdminCmdlet
1217
{
13-
[Parameter(Mandatory = false, Position = 0, ValueFromPipeline = true)]
18+
[Parameter(Mandatory = false, Position = 0, ValueFromPipeline = true, ParameterSetName = "Default")]
1419
public TenantSiteDesignPipeBind Identity;
1520

21+
/// <summary>
22+
/// When specified, returns built-in Microsoft site designs (store 1) instead of tenant-custom ones
23+
/// </summary>
24+
[Parameter(Mandatory = true, ParameterSetName = "BuiltIn")]
25+
public SwitchParameter BuiltIn;
26+
1627
protected override void ExecuteCmdlet()
1728
{
29+
if (ParameterSetName == "BuiltIn")
30+
{
31+
LogDebug("Retrieving built-in Microsoft site designs from store 1");
32+
33+
AdminContext.Load(AdminContext.Web, w => w.Url);
34+
AdminContext.ExecuteQueryRetry();
35+
36+
var results = SiteTemplates.GetBuiltInSiteDesigns(SharePointRequestHelper, AdminContext.Web.Url);
37+
38+
if (results?.Items != null)
39+
{
40+
WriteObject(results.Items.ToList(), true);
41+
}
42+
return;
43+
}
44+
1845
if (ParameterSpecified(nameof(Identity)))
1946
{
2047
var siteDesigns = Identity.GetTenantSiteDesign(Tenant);
2148

22-
if(siteDesigns == null || siteDesigns.Length == 0)
49+
if (siteDesigns == null || siteDesigns.Length == 0)
2350
{
2451
LogDebug("No site designs with the identity provided through Identity have been found");
2552
return;
@@ -37,4 +64,4 @@ protected override void ExecuteCmdlet()
3764
}
3865
}
3966
}
40-
}
67+
}

0 commit comments

Comments
 (0)