Skip to content

Commit

Permalink
Changed context implementation of PnPAdminCmdlets, added piping site …
Browse files Browse the repository at this point in the history
…scripts from webs and lists to site designs and list designs (#2928)

Co-authored-by: Gautam Sheth <[email protected]>
  • Loading branch information
KoenZomers and gautamdsheth authored Mar 24, 2023
1 parent e8247bd commit bf46387
Show file tree
Hide file tree
Showing 132 changed files with 536 additions and 489 deletions.
47 changes: 41 additions & 6 deletions documentation/Add-PnPListDesign.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ Creates a new List Design on the current tenant

## SYNTAX

### By SiteScript Instance (Default)

```powershell
Add-PnPListDesign -Title <String> -SiteScript <TenantSiteScriptPipeBind> [-Description <String>]
[-ListColor<TenantListDesignIcon>] [-ListIcon <TenantListDesignColor>] [-ThumbnailUrl <String>]
[-Connection <PnPConnection>]
```

### By SiteScript Ids

```powershell
Add-PnPListDesign -Title <String> -SiteScriptIds <Guid[]> [-Description <String>]
[-ListColor<TenantListDesignIcon>] [-ListIcon <TenantListDesignColor>] [-ThumbnailUrl <String>]
Expand All @@ -45,6 +55,20 @@ Add-PnPListDesign -Title "My Company Design" -SiteScriptIds "6def687f-0e08-4f1e-

Adds a new List Design, with the specified title, description and list color, list icon and thumbnail to be shown in the template picker. When applied it will run the scripts as referenced by the IDs. Use Get-PnPSiteScript to receive Site Scripts.

### EXAMPLE 3
```powershell
Get-PnPSiteScript -Identity "My List Script" | Add-PnPListDesign -Title "My Custom List"
```

Adds a new List Design, with the specified title based on a site script with the title "My List Script"

### EXAMPLE 4
```powershell
Get-PnPList -Identity "My List" | Get-PnPSiteScriptFromList | Add-PnPSiteScript -Title "My List Script" | Add-PnPListDesign -Title "My List"
```

Adds a new List Design and site script based on a list with the title "My List"

## PARAMETERS

### -Connection
Expand Down Expand Up @@ -75,12 +99,26 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -SiteScript
An instance, id or title of a site script to use for the list design
```yaml
Type: TenantSiteScriptPipeBind
Parameter Sets: By SiteScript Instance

Required: True
Position: Named
Default value: None
Accept pipeline input: True
Accept wildcard characters: False
```
### -SiteScriptIds
An array of guids of site scripts
An array of guids of site scripts to use for the list design
```yaml
Type: Guid[]
Parameter Sets: (All)
Parameter Sets: By SiteScript Ids

Required: True
Position: Named
Expand Down Expand Up @@ -145,7 +183,6 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -WhatIf
Shows what would happen if the cmdlet runs. The cmdlet is not run.
Expand All @@ -163,6 +200,4 @@ Accept wildcard characters: False
## RELATED LINKS
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
42 changes: 35 additions & 7 deletions documentation/Add-PnPSiteDesign.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,20 @@ Creates a new Site Design on the current tenant

## SYNTAX

### By SiteScript Instance (Default)

```powershell
Add-PnPSiteDesign -Title <String> -SiteScript <TenantSiteScriptPipeBind> [-Description <String>] [-IsDefault]
[-PreviewImageAltText <String>] [-PreviewImageUrl <String>] [-WebTemplate <SiteWebTemplate>]
[-ThumbnailUrl <String>] [-DesignPackageId <Guid>] [-Connection <PnPConnection>]
```

### By SiteScript Ids

```powershell
Add-PnPSiteDesign -Title <String> -SiteScriptIds <Guid[]> [-Description <String>] [-IsDefault]
[-PreviewImageAltText <String>] [-PreviewImageUrl <String>] [-WebTemplate <SiteWebTemplate>]
[-ThumbnailUrl <String>] [-DesignPackageId <Guid>]
[-Connection <PnPConnection>]
[-ThumbnailUrl <String>] [-DesignPackageId <Guid>] [-Connection <PnPConnection>]
```

## DESCRIPTION
Expand Down Expand Up @@ -53,6 +62,13 @@ Add-PnPSiteDesign -Title "My Company Design" -SiteScriptIds "e84dcb46-3ab9-4456-

Adds a new Site Design, with the specified title, description and logo to be shown in the template picker. When applied it will run the scripts as referenced by the IDs. Use Get-PnPSiteScript to receive Site Scripts. The WebTemplate parameter specifies that this design applies to modern Team Sites. Notice that when the location for the ThumbnailUrl contains a space, it should be provided URL decoded, so i.e. no %20 for spaces.

### EXAMPLE 4
```powershell
Get-PnPSiteScriptFromWeb -IncludeAll | Add-PnPSiteScript -Title "My Site Script" | Add-PnPSiteDesign -Title "My Site Design" -WebTemplate TeamSite
```

Adds a new Site Design based on the currently connected to site, with the specified title to be shown in the template picker.

## PARAMETERS

### -Confirm
Expand Down Expand Up @@ -140,12 +156,26 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -SiteScript
An instance, id or title of a site script to use for the site design
```yaml
Type: TenantSiteScriptPipeBind
Parameter Sets: By SiteScript Instance

Required: True
Position: Named
Default value: None
Accept pipeline input: True
Accept wildcard characters: False
```
### -SiteScriptIds
An array of guids of site scripts
An array of guids of site scripts to use for the site design
```yaml
Type: Guid[]
Parameter Sets: (All)
Parameter Sets: By SiteScript Ids

Required: True
Position: Named
Expand Down Expand Up @@ -228,6 +258,4 @@ Accept wildcard characters: False
## RELATED LINKS
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
63 changes: 56 additions & 7 deletions documentation/Get-PnPSiteScriptFromList.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,45 @@ Generates a Site Script from an existing list

## SYNTAX

### By List (Default)

```powershell
Get-PnPSiteScriptFromList -Identity <ListPipeBind> [-Connection <PnPConnection>] [-Verbose]
```

### By Url

```powershell
Get-PnPSiteScriptFromList -Url <String> [-Connection <PnPConnection>] [<CommonParameters>]
Get-PnPSiteScriptFromList -Url <String> [-Connection <PnPConnection>] [-Verbose]
```

## DESCRIPTION
This command allows a Site Script to be generated off of an existing list on your tenant. Connect to your SharePoint Online Admin site before executing this command.
This command allows a Site Script to be generated off of an existing list on your tenant. The script will return the JSON syntax with the definition of the list, including fields, views, content types, and some of the list settings. The script can then be used with [Add-PnPSiteScript](Add-PnPSiteScript.md) and [Add-PnPListDesign](Add-PnPListDesign.md) to allow lists with the same configuration as the original list to be created by end users.

## EXAMPLES

### EXAMPLE 1
```powershell
Get-PnPSiteScriptFromList -List "MyList"
```

Returns the generated Site Script JSON from the list "MyList" in the currently connected to site

### EXAMPLE 2
```powershell
Get-PnPList -Identity "MyList" | Get-PnPSiteScriptFromList | Add-PnPSiteScript -Title "MyListScript" | Add-PnPListDesign -Title "MyListDesign"
```

Returns the generated Site Script JSON from the list "MyList" in the currently connected to site and registers it as a new Site Script with the title "MyListScript" and uses that Site Script to register a new List Design with the title "MyListDesign"

### EXAMPLE 3
```powershell
Get-PnPSiteScriptFromList -Url "https://contoso.sharepoint.com/sites/teamsite/lists/MyList"
```

Returns the generated Site Script JSON from the list "MyList" at the provided Url

### EXAMPLE 2
### EXAMPLE 4
```powershell
Get-PnPSiteScriptFromList -Url "https://contoso.sharepoint.com/sites/teamsite/Shared Documents"
```
Expand Down Expand Up @@ -73,12 +95,26 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Identity
Specifies an instance, Id or, title of the list to generate a Site Script from
```yaml
Type: ListPipeBind
Parameter Sets: By List

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```
### -Url
Specifies the URL of the list to generate a Site Script from
Specifies the full URL of the list to generate a Site Script from. I.e. https://contoso.sharepoint.com/sites/teamsite/lists/MyList
```yaml
Type: String
Parameter Sets: (All)
Parameter Sets: By Url

Required: True
Position: Named
Expand All @@ -87,6 +123,20 @@ Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```
### -Verbose
When provided, additional debug statements will be shown while executing the cmdlet.
```yaml
Type: SwitchParameter
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -WhatIf
Shows what would happen if the cmdlet runs. The cmdlet is not run.
Expand All @@ -104,5 +154,4 @@ Accept wildcard characters: False
## RELATED LINKS
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
7 changes: 7 additions & 0 deletions documentation/Get-PnPSiteScriptFromWeb.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ Get-PnPSiteScriptFromWeb -IncludeAllLists

Returns the generated Site Script JSON containing all lists from the currently connected to site

### EXAMPLE 5
```powershell
Get-PnPSiteScriptFromWeb -IncludeAllLists | Add-PnPSiteScript -Title "My Site Script" | Add-PnPSiteDesign -Title "My Site Design" -WebTemplate TeamSite
```

Creates a new site script and site design based on the currently connected to site

## PARAMETERS

### -IncludeAll
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Admin/AddHubSiteAssociation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class AddHubSiteAssociation : PnPAdminCmdlet
protected override void ExecuteCmdlet()
{
Tenant.ConnectSiteToHubSite(Site.Url, HubSite.Url);
ClientContext.ExecuteQueryRetry();
AdminContext.ExecuteQueryRetry();
}
}
}
20 changes: 10 additions & 10 deletions src/Commands/Admin/AddHubToHubAssociation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ protected override void ExecuteCmdlet()
if (ParameterSetName == ParamSet_ById)
{
HubSiteProperties sourceProperties = Tenant.GetHubSitePropertiesById(Source);
ClientContext.Load(sourceProperties);
AdminContext.Load(sourceProperties);
sourceProperties.ParentHubSiteId = Target;
sourceProperties.Update();
ClientContext.ExecuteQueryRetry();
AdminContext.ExecuteQueryRetry();
}
else
{
SiteProperties sourceSiteProperties = Tenant.GetSitePropertiesByUrl(SourceUrl, true);
ClientContext.Load(sourceSiteProperties);
ClientContext.ExecuteQueryRetry();
AdminContext.Load(sourceSiteProperties);
AdminContext.ExecuteQueryRetry();

SiteProperties destSiteProperties = Tenant.GetSitePropertiesByUrl(TargetUrl, true);
ClientContext.Load(destSiteProperties);
ClientContext.ExecuteQueryRetry();
AdminContext.Load(destSiteProperties);
AdminContext.ExecuteQueryRetry();

if (!sourceSiteProperties.IsHubSite)
{
Expand All @@ -60,13 +60,13 @@ protected override void ExecuteCmdlet()
}

HubSiteProperties sourceProperties = Tenant.GetHubSitePropertiesByUrl(SourceUrl);
ClientContext.Load(sourceProperties);
AdminContext.Load(sourceProperties);
Microsoft.SharePoint.Client.Site targetSite = Tenant.GetSiteByUrl(TargetUrl);
ClientContext.Load(targetSite);
ClientContext.ExecuteQueryRetry();
AdminContext.Load(targetSite);
AdminContext.ExecuteQueryRetry();
sourceProperties.ParentHubSiteId = targetSite.HubSiteId;
sourceProperties.Update();
ClientContext.ExecuteQueryRetry();
AdminContext.ExecuteQueryRetry();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Admin/AddMicrosoft365GroupToSite.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using Microsoft.Online.SharePoint.TenantAdministration;
using Microsoft.SharePoint.Client;

using PnP.PowerShell.Commands.Base;
using System.Management.Automation;
using PnP.Framework.Sites;
using System.Management.Automation;
using System;

namespace PnP.PowerShell.Commands.Admin
Expand Down Expand Up @@ -37,6 +36,7 @@ public class AddMicrosoft365GroupToSite: PnPAdminCmdlet

[Parameter(Mandatory = false)]
public string[] Owners;

protected override void ExecuteCmdlet()
{
var groupifyInformation = new TeamSiteCollectionGroupifyInformation()
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Admin/AddOrgAssetsLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class AddOrgAssetsLibrary : PnPAdminCmdlet
protected override void ExecuteCmdlet()
{
Tenant.AddToOrgAssetsLibAndCdnWithType(CdnType, LibraryUrl, ThumbnailUrl, OrgAssetType);
ClientContext.ExecuteQueryRetry();
AdminContext.ExecuteQueryRetry();
}
}
}
3 changes: 1 addition & 2 deletions src/Commands/Admin/AddOrgNewsSite.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.SharePoint.Client;

using PnP.PowerShell.Commands.Base;
using System.Management.Automation;
using PnP.PowerShell.Commands.Base.PipeBinds;
Expand All @@ -15,7 +14,7 @@ public class AddOrgNewsSite : PnPAdminCmdlet
protected override void ExecuteCmdlet()
{
Tenant.SetOrgNewsSite(OrgNewsSiteUrl.Url);
ClientContext.ExecuteQueryRetry();
AdminContext.ExecuteQueryRetry();
}
}
}
2 changes: 1 addition & 1 deletion src/Commands/Admin/AddSiteCollectionAppCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected override void ExecuteCmdlet()
}

Tenant.GetSiteByUrl(url).RootWeb.TenantAppCatalog.SiteCollectionAppCatalogsSites.Add(url);
ClientContext.ExecuteQueryRetry();
AdminContext.ExecuteQueryRetry();
}
}
}
Loading

0 comments on commit bf46387

Please sign in to comment.