Skip to content

Commit

Permalink
Added new cmdlet to return modern page scheduling enabled status
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinvanhunen committed May 31, 2024
1 parent 3db83bc commit 4ac757f
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
53 changes: 53 additions & 0 deletions documentation/Get-PnPPageSchedulingEnabled.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
Module Name: PnP.PowerShell
schema: 2.0.0
applicable: SharePoint Online
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPPageSchedulingEnabled.html
external help file: PnP.PowerShell.dll-Help.xml
title: Get-PnPPageSchedulingEnabled
---

# Get-PnPPageSchedulingEnabled

## SYNOPSIS

Return true of false, reflecting the state of the modern page schedule feature

## SYNTAX

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

## DESCRIPTION

This will return a boolean value stating if the modern page schedule feature has been enabled or not.

## EXAMPLES

### EXAMPLE 1
```powershell
Get-PnPPageSchedulingEnabled
```

This will return a boolean value stating if the modern page schedule feature has been enabled or not.

## PARAMETERS

### -Connection
Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection.

```yaml
Type: PnPConnection
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
## RELATED LINKS
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
34 changes: 34 additions & 0 deletions src/Commands/Pages/GetPageSchedulingEnabled.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Management.Automation;
using System.Text.Json;
using PnP.PowerShell.Commands.Utilities;

namespace PnP.PowerShell.Commands.Pages
{
[Cmdlet(VerbsCommon.Get, "PnPPageSchedulingEnabled")]
[OutputType(typeof(void))]
public class GetPageSchedulingEnabled : PnPWebCmdlet
{
protected override void ExecuteCmdlet()
{
var pagesList = PagesUtility.GetModernPagesLibrary(PnPContext.Web);
var payload = new
{
parameters = new
{
AddRequiredFields = false,
RenderOptions = 16385
}
};

var results = Utilities.REST.RestHelper.PostAsync<JsonElement>(Connection.HttpClient, $"{PnPContext.Web.Url}/_api/web/lists(guid'{pagesList.Id}')/RenderListDataAsStream", ClientContext, payload, false).GetAwaiter().GetResult();

var frameworkClientInfo = results.GetProperty("SPFrameworkClientInfo");
var pageContextJson = frameworkClientInfo.GetProperty("PageContextJson");
var value = pageContextJson.GetString();
var contextElement = JsonDocument.Parse(value);
var pageContextInfoElement = contextElement.RootElement.GetProperty("spPageContextInfo");
var listPageScheduling = pageContextInfoElement.GetProperty("listPageSchedulingEnabled").GetBoolean();
WriteObject(listPageScheduling);
}
}
}

0 comments on commit 4ac757f

Please sign in to comment.