Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2459 from KoenZomers/AddGetSiteScriptFromWebAndList
Browse files Browse the repository at this point in the history
Adding Get-PnPSiteScriptFromList and Get-PnPSiteScriptFromWeb commands
  • Loading branch information
erwinvanhunen authored Feb 9, 2020
2 parents 0fe366d + 02dd880 commit 2c5258f
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Commands/SharePointPnP.PowerShell.Commands.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,8 @@
<Compile Include="SiteDesigns\GetSiteDesignRun.cs" />
<Compile Include="SiteDesigns\AddSiteDesignTask.cs" />
<Compile Include="Search\RemoveSearchConfiguration.cs" />
<Compile Include="SiteDesigns\GetSiteScriptFromList.cs" />
<Compile Include="SiteDesigns\GetSiteScriptFromWeb.cs" />
<Compile Include="SiteDesigns\InvokeSiteDesign.cs" />
<Compile Include="SiteDesigns\RemoveSiteDesignTask.cs" />
<Compile Include="SiteDesigns\SetSiteDesign.cs" />
Expand Down
36 changes: 36 additions & 0 deletions Commands/SiteDesigns/GetSiteScriptFromList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#if !ONPREMISES
using Microsoft.Online.SharePoint.TenantAdministration;
using Microsoft.SharePoint.Client;
using SharePointPnP.PowerShell.CmdletHelpAttributes;
using SharePointPnP.PowerShell.Commands.Base;
using System.Management.Automation;

namespace SharePointPnP.PowerShell.Commands
{
[Cmdlet(VerbsCommon.Get, "PnPSiteScriptFromList", SupportsShouldProcess = true)]
[CmdletHelp(@"Generates a Site Script from an existing list",
DetailedDescription = "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.",
Category = CmdletHelpCategory.TenantAdmin,
SupportedPlatform = CmdletSupportedPlatform.Online)]
[CmdletExample(
Code = @"PS:> Get-PnPSiteScriptFromList -Url https://contoso.sharepoint.com/sites/teamsite/lists/MyList",
Remarks = @"Returns the generated Site Script JSON from the list ""MyList"" at the provided Url",
SortOrder = 1)]
[CmdletExample(
Code = @"PS:> Get-PnPSiteScriptFromList -Url ""https://contoso.sharepoint.com/sites/teamsite/Shared Documents""",
Remarks = "Returns the generated Site Script JSON from the default document library at the provided Url",
SortOrder = 2)]
public class GetSiteScriptFromList : PnPAdminCmdlet
{
[Parameter(Mandatory = true, HelpMessage = "Specifies the URL of the list to generate a Site Script from", ValueFromPipeline = true)]
public string Url;

protected override void ExecuteCmdlet()
{
var script = Tenant.GetSiteScriptFromList(ClientContext, Url);
ClientContext.ExecuteQueryRetry();
WriteObject(script.Value);
}
}
}
#endif
73 changes: 73 additions & 0 deletions Commands/SiteDesigns/GetSiteScriptFromWeb.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#if !ONPREMISES
using Microsoft.Online.SharePoint.TenantAdministration;
using Microsoft.SharePoint.Client;
using SharePointPnP.PowerShell.CmdletHelpAttributes;
using SharePointPnP.PowerShell.Commands.Base;
using System.Management.Automation;

namespace SharePointPnP.PowerShell.Commands
{
[Cmdlet(VerbsCommon.Get, "PnPSiteScriptFromWeb", SupportsShouldProcess = true)]
[CmdletHelp(@"Generates a Site Script from an existing site",
DetailedDescription = "This command allows a Site Script to be generated off of an existing site on your tenant. Connect to your SharePoint Online Admin site before executing this command.",
Category = CmdletHelpCategory.TenantAdmin,
SupportedPlatform = CmdletSupportedPlatform.Online)]
[CmdletExample(
Code = @"PS:> Get-PnPSiteScriptFromWeb -Url https://contoso.sharepoint.com/sites/teamsite -IncludeAll",
Remarks = "Returns the generated Site Script JSON containing all supported components from the site at the provided Url",
SortOrder = 1)]
[CmdletExample(
Code = @"PS:> Get-PnPSiteScriptFromWeb -Url https://contoso.sharepoint.com/sites/teamsite -IncludeAll -Lists ""Shared Documents"",""Lists\MyList""",
Remarks = @"Returns the generated Site Script JSON containing all supported components from the site at the provided Url including the lists ""Shared Documents"" and ""MyList""",
SortOrder = 2)]
[CmdletExample(
Code = @"PS:> Get-PnPSiteScriptFromWeb -Url https://contoso.sharepoint.com/sites/teamsite -IncludeBranding -IncludeLinksToExportedItems",
Remarks = "Returns the generated Site Script JSON containing the branding and navigation links from the site at the provided Url",
SortOrder = 3)]
public class GetSiteScriptFromWeb : PnPAdminCmdlet
{
private const string ParameterSet_ALLCOMPONENTS = "All components";
private const string ParameterSet_SPECIFICCOMPONENTS = "Specific components";

[Parameter(Mandatory = true, HelpMessage = "Specifies the URL of the site to generate a Site Script from", ValueFromPipeline = true)]
public string Url;

[Parameter(Mandatory = false, HelpMessage = @"Allows specifying one or more site relative URLs of lists that should be included into the Site Script, i.e. ""Shared Documents"",""List\MyList""")]
public string[] Lists;

[Parameter(Mandatory = false, HelpMessage = "If specified will include all supported components into the Site Script", ParameterSetName = ParameterSet_ALLCOMPONENTS)]
public SwitchParameter IncludeAll;

[Parameter(Mandatory = false, HelpMessage = "If specified will include the branding of the site into the Site Script", ParameterSetName = ParameterSet_SPECIFICCOMPONENTS)]
public SwitchParameter IncludeBranding;

[Parameter(Mandatory = false, HelpMessage = "If specified will include navigation links into the Site Script", ParameterSetName = ParameterSet_SPECIFICCOMPONENTS)]
public SwitchParameter IncludeLinksToExportedItems;

[Parameter(Mandatory = false, HelpMessage = "If specified will include the regional settings into the Site Script", ParameterSetName = ParameterSet_SPECIFICCOMPONENTS)]
public SwitchParameter IncludeRegionalSettings;

[Parameter(Mandatory = false, HelpMessage = "If specified will include the external sharing configuration into the Site Script", ParameterSetName = ParameterSet_SPECIFICCOMPONENTS)]
public SwitchParameter IncludeSiteExternalSharingCapability;

[Parameter(Mandatory = false, HelpMessage = "If specified will include the branding of the site into the Site Script", ParameterSetName = ParameterSet_SPECIFICCOMPONENTS)]
public SwitchParameter IncludeTheme;

protected override void ExecuteCmdlet()
{
var tenantSiteScriptSerializationInfo = new TenantSiteScriptSerializationInfo
{
IncludeBranding = IncludeBranding || IncludeAll,
IncludedLists = Lists,
IncludeLinksToExportedItems = IncludeLinksToExportedItems || IncludeAll,
IncludeRegionalSettings = IncludeRegionalSettings || IncludeAll,
IncludeSiteExternalSharingCapability = IncludeSiteExternalSharingCapability || IncludeAll,
IncludeTheme = IncludeTheme || IncludeAll
};
var script = Tenant.GetSiteScriptFromSite(Url, tenantSiteScriptSerializationInfo);
ClientContext.ExecuteQueryRetry();
WriteObject(script.Value.JSON);
}
}
}
#endif

0 comments on commit 2c5258f

Please sign in to comment.