diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c76687da..b826e8ef8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/documentation/Get-PnPPage.md b/documentation/Get-PnPPage.md index 3c555ad3b..441f4ae23 100644 --- a/documentation/Get-PnPPage.md +++ b/documentation/Get-PnPPage.md @@ -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 [-Connection ] ``` +### All pages + +```powershell +Get-PnPPage [-Connection ] +``` + ## 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 @@ -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 @@ -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 @@ -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) \ No newline at end of file diff --git a/src/Commands/Pages/GetPage.cs b/src/Commands/Pages/GetPage.cs index 7b93c0b12..84542a02b 100644 --- a/src/Commands/Pages/GetPage.cs +++ b/src/Commands/Pages/GetPage.cs @@ -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), 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); + } } } } \ No newline at end of file