Skip to content

Commit

Permalink
Refactor Export-PnPPage cmdlet to add support for returning the templ…
Browse files Browse the repository at this point in the history
…ate as an in-memory object (#4323)

Co-authored-by: Gautam Sheth <[email protected]>
  • Loading branch information
gautamdsheth and Gautam Sheth authored Sep 20, 2024
1 parent 0306f2f commit 315c14a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
9 changes: 3 additions & 6 deletions documentation/Export-PnPPage.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Exports a Client Side Page to a PnP Provisioning Template

```powershell
Export-PnPPage [-Identity] <PagePipeBind> [-PersistBrandingFiles] [-Out <String>] [-Force]
[-Configuration <ExtractConfigurationPipeBind>] [-Connection <PnPConnection>]
[-Configuration <ExtractConfigurationPipeBind>] [-OutputInstance] [-Connection <PnPConnection>]
```

Expand Down Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions src/Commands/Pages/ExportPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -95,9 +98,15 @@ private void ExtractTemplate(string dirName, string fileName, ExtractConfigurati
}
else
{
WriteObject(outputTemplate.ToXML());
if (OutputInstance)
{
WriteObject(outputTemplate);
}
else
{
WriteObject(outputTemplate.ToXML());
}
}
}
}

}

0 comments on commit 315c14a

Please sign in to comment.