Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `-Name` parameter to `Add-PnPApplicationCustomizer` cmdlet to allow for specifying the name of the application customizer [#4767](https://github.com/pnp/powershell/pull/4767)
- Added `Get-PnPTraceLog` cmdlet which allows reading from the detailed in memory logs of the PnP PowerShell cmdlet execution [#4794](https://github.com/pnp/powershell/pull/4794)
- Added `-Transitive` parameter to `Get-PnPAzureADGroupMember` cmdlet to allow members of groups inside groups to be retrieved [#4799](https://github.com/pnp/powershell/pull/4799)
- Added the ability to `Get-PnPPage` to return all site pages in the site by omitting the `-Identity` parameter [#4805](https://github.com/pnp/powershell/pull/4805)

### Changed

Expand Down
28 changes: 21 additions & 7 deletions documentation/Get-PnPPage.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,27 @@ online version: https://pnp.github.io/powershell/cmdlets/Get-PnPPage.html
# Get-PnPPage

## SYNOPSIS
Returns a modern page
Returns a specific or all modern pages (Site Pages) in a SharePoint site.

## SYNTAX

### Specific page

```powershell
Get-PnPPage -Identity <PagePipeBind> [-Connection <PnPConnection>]
```

### All pages

```powershell
Get-PnPPage [-Connection <PnPConnection>]
```

## DESCRIPTION
This command allows the retrieval of a modern sitepage along with its properties and contents on it. Note that for a newly created modern site, the Columns and Sections of the Home.aspx page will not be filled according to the actual site page contents. This is because the underlying CanvasContent1 will not be populated until the homepage has been edited and published. The reason for this behavior is to allow for the default homepage to be able to be updated by Microsoft as long as it hasn't been modified. For any other site page or after editing and publishing the homepage, this command will return the correct columns and sections as they are positioned on the site page.

Also note that if you want to retrieve all site pages in a site by omitting the -Identity parameter, the command will return all pages in the Site Pages library, but with less details and will require SharePoint Online Administrator permissions to do so. This is how it has been designed on the server side. If you want the full details on all pages, you can do it as follows `Get-PnPPage | % { Get-PnPPage -Identity $_.Name }`. Be aware that this causes a lot of server calls and is much slower than the first command.

## EXAMPLES

### EXAMPLE 1
Expand Down Expand Up @@ -51,6 +61,13 @@ Get-PnPPage -Identity "MyPage.aspx" -Web (Get-PnPWeb -Identity "Subsite1")

Gets the page named 'MyPage.aspx' from the subsite named 'Subsite1'

### EXAMPLE 5
```powershell
Get-PnPPage
```

Returns all site pages in the current SharePoint site. Note that this will return less details than when using the -Identity parameter and requires SharePoint Online Administrator permissions to do so.

## PARAMETERS

### -Connection
Expand All @@ -68,11 +85,11 @@ Accept wildcard characters: False
```

### -Identity
The name of the page
The name of the page to retrieve

```yaml
Type: PagePipeBind
Parameter Sets: (All)
Parameter Sets: Specific page

Required: True
Position: 0
Expand All @@ -81,9 +98,6 @@ Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```



## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
41 changes: 33 additions & 8 deletions src/Commands/Pages/GetPage.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,52 @@
using PnP.PowerShell.Commands.Base.Completers;
using Microsoft.Online.SharePoint.TenantAdministration;
using Microsoft.SharePoint.Client;
using PnP.PowerShell.Commands.Base.Completers;
using PnP.PowerShell.Commands.Base.PipeBinds;
using PnP.PowerShell.Commands.Utilities;
using System;
using System.Collections.Generic;
using System.Management.Automation;
using System.Reflection.Metadata;

namespace PnP.PowerShell.Commands.Pages
{
[Cmdlet(VerbsCommon.Get, "PnPPage")]
[Cmdlet(VerbsCommon.Get, "PnPPage", DefaultParameterSetName = ParameterSet_ALL)]
[Alias("Get-PnPClientSidePage")]
[OutputType(typeof(PnP.Core.Model.SharePoint.IPage))]
[OutputType(typeof(Core.Model.SharePoint.IPage), ParameterSetName = new[] { ParameterSet_SPECIFICPAGE })]
[OutputType(typeof(IEnumerable<SPSitePage>), ParameterSetName = new[] { ParameterSet_ALL })]
public class GetPage : PnPWebCmdlet
{
[Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0)]
private const string ParameterSet_SPECIFICPAGE = "Specific page";
private const string ParameterSet_ALL = "All pages";

[Parameter(Mandatory = false, ValueFromPipeline = true, Position = 0, ParameterSetName = ParameterSet_SPECIFICPAGE)]
[ArgumentCompleter(typeof(PageCompleter))]
public PagePipeBind Identity;

protected override void ExecuteCmdlet()
{
var clientSidePage = Identity.GetPage(Connection);
if (!ParameterSpecified(nameof(Identity)))
{
var tenantUrl = Connection.TenantAdminUrl ?? UrlUtilities.GetTenantAdministrationUrl(ClientContext.Url);

using var tenantContext = ClientContext.Clone(tenantUrl);
var tenant = new Tenant(tenantContext);

CurrentWeb.EnsureProperty(w => w.Url);
var pages = tenant.GetSPSitePages(CurrentWeb.Url);
tenantContext.ExecuteQueryRetry();

WriteObject(pages, true);
}
else
{
var clientSidePage = Identity.GetPage(Connection);

if (clientSidePage == null)
throw new Exception($"Page '{Identity?.Name}' does not exist");
if (clientSidePage == null)
throw new Exception($"Page '{Identity?.Name}' does not exist");

WriteObject(clientSidePage);
WriteObject(clientSidePage);
}
}
}
}
Loading