This repository has been archived by the owner on Jan 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 662
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2459 from KoenZomers/AddGetSiteScriptFromWebAndList
Adding Get-PnPSiteScriptFromList and Get-PnPSiteScriptFromWeb commands
- Loading branch information
Showing
3 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |