2

I want to create modern page in a modern site using CSOM PowerShell instead of PNP. After creating that I need to configure list and Events we part in that.

Please guide me on this.

Thanks in advance!

1 Answer 1

1

You can use the below csom script to create modern page:

$siteUrl="https://tenant.sharepoint.com/sites/michael"
$ListName="Site Pages"
$UserName="michael"
$Password ="password"
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Context.Credentials = $credentials
$List = $Context.web.Lists.GetByTitle($ListName)
$item=$list.RootFolder.Files.AddTemplateFile("/sites/michael/SitePages/ModernPage.aspx",[Microsoft.SharePoint.Client.TemplateFileType]::ClientSidePage).ListItemAllFields
$item["ContentTypeId"] = "0x0101009D1CB255DA76424F860D91F20E6C4118";
$item["Title"]="ModernPage"
$item["ClientSideApplicationId"] = "b6917cb1-93a0-4b97-a84d-7cf49975d4ec"
$item["PageLayoutType"] = "Article"
$item["PromotedState"] = "0"
$item["CanvasContent1"] = "<div></div>"
$item["BannerImageUrl"] = "/_layouts/15/images/sitepagethumbnail.png"
$item.Update()
$context.ExecuteQuery()
    
2
  • Thanks a lot for putting your time, Michael. Can I insert/configure the default webparts like "Events","Announcement" while creating the modern page? Commented Nov 16, 2020 at 6:24
  • As far as I know, there is no CSOM API's to add webparts to modern page. You'd better use PNP powershell to add web parts to modern page. Commented Nov 16, 2020 at 6:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.