Enabling scheduling on Publishing Pages in SharePoint Online (Office 365) using CSOM and PowerShell

Scheduling is easily enabled through the web interface when configuring the "Pages" library, but when deploying solutions using PowerShell, this must be automated as part of the configuration. Unfortunately, as many other sources also state, this is not directly supported in the Client Side API (CSOM).

The solution is to manually set up the Pages library the same way Microsoft does by adding two event receivers, changing some columns from hidden to visible and adding them to the default view.

Note: This example uses commands from the Office Dev PnP PowerShell library, ex. "Get-SPOContext". I recommend using this library for working this PowerShell and SharePoint (both Online and On-Premises).

Function to enable Scheduling on a library on a given web site:

https://gist.github.com/aflyen/f779232ec529d45c524f

On line 11 an additional function is needed to create the parameters for the "Load" method:

https://gist.github.com/aflyen/4a098b69b9faa43fd1a3

How to enable scheduling:

https://gist.github.com/aflyen/9fe012e018aba224f507