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; } // Generate site script var tenantSiteScriptSerializationInfo = new TenantSiteScriptSerializationInfo { IncludeBranding = IncludeBranding || IncludeAll, IncludedLists = Lists?.Select(l => l.Replace("\\", "/")).ToArray(), IncludeLinksToExportedItems = IncludeLinksToExportedItems || IncludeAll, IncludeRegionalSettings = IncludeRegionalSettings || IncludeAll, IncludeSiteExternalSharingCapability = IncludeSiteExternalSharingCapability || IncludeAll, IncludeTheme = IncludeTheme || IncludeAll }; var generatedSiteScript = Tenant.GetSiteScriptFromSite(Url, tenantSiteScriptSerializationInfo); ClientContext.ExecuteQueryRetry(); var siteScript = generatedSiteScript.Value.JSON; // Add the site script as a new site script to the tenant TenantSiteScriptCreationInfo siteScriptCreationInfo = new TenantSiteScriptCreationInfo { Title = Title, Description = Description, Content = siteScript }; var addedSiteScript = Tenant.CreateSiteScript(siteScriptCreationInfo); ClientContext.Load(addedSiteScript); ClientContext.ExecuteQueryRetry(); // Create a site design TenantSiteDesignCreationInfo siteDesignInfo = new TenantSiteDesignCreationInfo { Title = Title, SiteScriptIds = new [] { addedSiteScript.Id }, Description = Description, IsDefault = IsDefault, PreviewImageAltText = PreviewImageAltText, PreviewImageUrl = PreviewImageUrl, WebTemplate = ((int)WebTemplate).ToString(), ThumbnailUrl = ThumbnailUrl, DesignPackageId = DesignPackageId }; var design = Tenant.CreateSiteDesign(siteDesignInfo); ClientContext.Load(design); ClientContext.ExecuteQueryRetry(); WriteObject(design); }
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); }
//gavdcodeend 31 //gavdcodebegin 32 static void SpCsCsomGenerateWebSiteScript(ClientContext spCtx) { Tenant myTenant = new Tenant(spCtx); TenantSiteScriptSerializationInfo myInfo = new TenantSiteScriptSerializationInfo() { IncludeBranding = true, IncludeTheme = true, IncludeRegionalSettings = true, IncludeLinksToExportedItems = true, IncludeSiteExternalSharingCapability = true, IncludedLists = new[] { "Shared Documents", "Lists/TestList" } }; var response = myTenant.GetSiteScriptFromSite( "https://[domain].sharepoint.com/sites/Test_Guitaca/", myInfo); spCtx.ExecuteQuery(); Console.WriteLine(response.Value.JSON); }
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; } var tenantSiteScriptSerializationInfo = new TenantSiteScriptSerializationInfo { IncludeBranding = IncludeBranding || IncludeAll, IncludedLists = Lists?.Select(l => l.Replace("\\", "/")).ToArray(), IncludeLinksToExportedItems = IncludeLinksToExportedItems || IncludeAll, IncludeRegionalSettings = IncludeRegionalSettings || IncludeAll, IncludeSiteExternalSharingCapability = IncludeSiteExternalSharingCapability || IncludeAll, IncludeTheme = IncludeTheme || IncludeAll }; var script = Tenant.GetSiteScriptFromSite(Url, tenantSiteScriptSerializationInfo); ClientContext.ExecuteQueryRetry(); WriteObject(script.Value.JSON); }
protected override void ExecuteCmdlet() { // Retrieve the provided site design var siteDesigns = Identity.GetTenantSiteDesign(Tenant); // Ensure a site design has been found if (siteDesigns == null || siteDesigns.Length == 0) { throw new PSArgumentException("Site design provided through the Identity parameter could not be found. Use Add-PnPSiteDesignFromWeb if you intend on adding a new site design.", nameof(Identity)); } // Ensure we only have one site design so we're sure which one needs to be updated if (siteDesigns.Length > 1) { throw new PSArgumentException("Multiple site designs have been found based on the name provided through the Identity parameter. Please use the site design Id instead to specify only one site design to update.", nameof(Identity)); } var siteDesign = siteDesigns[0]; // Generate site script WriteVerbose($"Generating site script from {Url}"); var tenantSiteScriptSerializationInfo = new TenantSiteScriptSerializationInfo { IncludeBranding = IncludeBranding || IncludeAll, IncludedLists = Lists?.Select(l => l.Replace("\\", "/")).ToArray(), IncludeLinksToExportedItems = IncludeLinksToExportedItems || IncludeAll, IncludeRegionalSettings = IncludeRegionalSettings || IncludeAll, IncludeSiteExternalSharingCapability = IncludeSiteExternalSharingCapability || IncludeAll, IncludeTheme = IncludeTheme || IncludeAll }; var generatedSiteScript = Tenant.GetSiteScriptFromSite(Url, tenantSiteScriptSerializationInfo); ClientContext.ExecuteQueryRetry(); var siteScript = generatedSiteScript.Value.JSON; // Retrieve the sitescripts linked to the site design siteDesign.EnsureProperty(d => d.SiteScriptIds); bool addAsNewSiteScript = false; if (siteDesign.SiteScriptIds.Length > 0) { // One or more site scripts exist in the site design if (siteDesign.SiteScriptIds.Length > 1) { // Multiple site scripts in the site design WriteVerbose($"Site design provided through the Identity parameter contains {siteDesign.SiteScriptIds.Length} site scripts. The first one will be overwritten with a new template from the site."); } else { // One site script exists in the site design, which is the expected scenario WriteVerbose($"Site design provided through the Identity parameter contains {siteDesign.SiteScriptIds.Length} site script. It will be overwritten with a new template from the site."); } // Update an existing site script try { var script = Tenant.GetSiteScript(ClientContext, siteDesign.SiteScriptIds.First()); script.Content = siteScript; Tenant.UpdateSiteScript(script); ClientContext.ExecuteQueryRetry(); } catch (Microsoft.SharePoint.Client.ServerException e) when(e.ServerErrorTypeName == "System.IO.FileNotFoundException") { // Thrown when a site script is still referenced in the site design, but the actual site script has been removed. This likely means the site design is now in an orphaned state and cannot be used anymore. Going to try anyway. WriteVerbose($"Site design provided through the Identity parameter contains a reference to site script {siteDesign.SiteScriptIds.First()} which no longer exists. Will try to add it as a new site script but it likely will fail as the site design is now orphaned. Remove the site design and create a new one if it keeps failing."); addAsNewSiteScript = true; } } else { // No site scripts in the site design WriteVerbose($"Site design provided through the Identity parameter does not contain any site scripts yet. Adding a new site script to the site design."); addAsNewSiteScript = true; } if (addAsNewSiteScript) { // Add the site script as a new site script to the tenant TenantSiteScriptCreationInfo siteScriptCreationInfo = new TenantSiteScriptCreationInfo { Title = siteDesign.Title, Description = siteDesign.Description, Content = siteScript }; var addedSiteScript = Tenant.CreateSiteScript(siteScriptCreationInfo); ClientContext.Load(addedSiteScript); ClientContext.ExecuteQueryRetry(); // Connect the site script to the site design siteDesign.SiteScriptIds = new[] { addedSiteScript.Id }; Tenant.UpdateSiteDesign(siteDesign); ClientContext.ExecuteQueryRetry(); } WriteObject(siteDesign); }