From c8199c7f5d1e0bc7afd6560dd390217bacb76398 Mon Sep 17 00:00:00 2001 From: Gautam Sheth Date: Fri, 20 Sep 2024 20:50:51 +0300 Subject: [PATCH] Refactor Export-PnPPage cmdlet to add support for returning the template as an in-memory object --- documentation/Export-PnPPage.md | 9 +++------ src/Commands/Pages/ExportPage.cs | 13 +++++++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/documentation/Export-PnPPage.md b/documentation/Export-PnPPage.md index 37ff5cab1..3bd629b7f 100644 --- a/documentation/Export-PnPPage.md +++ b/documentation/Export-PnPPage.md @@ -16,7 +16,7 @@ Exports a Client Side Page to a PnP Provisioning Template ```powershell Export-PnPPage [-Identity] [-PersistBrandingFiles] [-Out ] [-Force] - [-Configuration ] [-Connection ] + [-Configuration ] [-OutputInstance] [-Connection ] ``` @@ -141,15 +141,12 @@ Accept pipeline input: False Accept wildcard characters: False ``` - - -### -WhatIf -Shows what would happen if the cmdlet runs. The cmdlet is not run. +### -OutputInstance +Returns the template as an in-memory object, which is an instance of the SiteTemplate type of the PnP Core Component. It cannot be used together with the -Out parameter. ```yaml Type: SwitchParameter Parameter Sets: (All) -Aliases: wi Required: False Position: Named diff --git a/src/Commands/Pages/ExportPage.cs b/src/Commands/Pages/ExportPage.cs index 4c6236de0..228e06e57 100644 --- a/src/Commands/Pages/ExportPage.cs +++ b/src/Commands/Pages/ExportPage.cs @@ -29,6 +29,9 @@ public class ExportPage : PnPWebCmdlet [Parameter(Mandatory = false)] public ExtractConfigurationPipeBind Configuration; + [Parameter(Mandatory = false)] + public SwitchParameter OutputInstance; + protected override void ProcessRecord() { _ = Identity.GetPage(Connection) ?? throw new Exception($"Page '{Identity?.Name}' does not exist"); @@ -95,9 +98,15 @@ private void ExtractTemplate(string dirName, string fileName, ExtractConfigurati } else { - WriteObject(outputTemplate.ToXML()); + if (OutputInstance) + { + WriteObject(outputTemplate); + } + else + { + WriteObject(outputTemplate.ToXML()); + } } } } - } \ No newline at end of file