1

I am working on a power shell script with CSOM to copy/export all the web parts from one source page and import them to another target page in the site pages library In Office 365 site.

I am using following command to get the object of current target/source page.

$Page = $ctx.Web.GetFileByServerRelativeUrl($PageURL)

Now the object returned with this method does not support any property or method that shows whether current page is a web part page or wiki page. If the page is a wiki page then and then only we need to add webpart zone and then add webparts to them.

Web part pages as we know have predefined layouts with webpart zones already added.. so we can add the copied web part within webpartzones with webpartzone id like "Left Column" using following command

$pageWPManager.AddWebPart($webpartdef,$WebPartZoneID,$WebPartZoneIndex)

where

$WebPartZoneID can be "Left Column", "Body" etc.

$WebPartZoneIndex can be index like 0,1,2,etc.

But in case of wiki page we need to pass either

$WebPartZoneID = ""

or we can first add a webpart zone in wiki page and then add the webpart there.

But since i am looping on all pages of the library, i first need to decide whether current page is wiki page or webpart page..

Is there a way to do this with Powershell and CSOM for an O365 or SP Online page?

Any help would be appreciated..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.