One of the challenges with working with the Client Object model for SharePoint Online is working without the publishing API. You need to be quite inventive to carry out some tasks which could be achieved natively with the Publishing API. Quite often I have found a need to invoke a work around to meet one of the following scenarios, so I thought I would share this with you (all of the examples below are assuming that you have instantiated a connection to SharePoint Online and have active client context and web objects).
The more I started looking into providing these snippets of PowerShell, the more I started to think about other common tasks and pieces of functionality which are often needed when working with SharePoint Online and this is what this post is all about. So hopefully the following will be helpful to anyone facing the same challenges.
Working with Page Layouts
With more and more talk coming back about when not to use web templates on SharePoint Online, you often you need to amend or set what the default and available page layout(s) are for a given SharePoint site. Luckily, this information is stored in the given web properties of the site. So if you are on SharePoint Online, you can re-use the following function which does both:
Note: this code was originally adapted from the following article: http://habaneroconsulting.com/insights/setting-available-and-default-page-layouts-in-sharepoint-online#.VEjTJfnF8SV
Another common scenario is when you need to amend what the default page is for a site is. Again, this is pretty straight forward by using the following function:
Break Web Inheritance
The following function takes the path to an XML file which contains a site structure for which we need to break the permissions inheritance: