I am facing error:"the given key was not present in the dictionary " while i am creating publishing page in sharepoint online using powershell CSOM.
Here is my code:
$subsiteCtx=New-Object Microsoft.SharePoint.Client.ClientContext($subsiteUrl)
$subsiteCtx.Credentials = $credentials
$subsiteCtx.ExecuteQuery()
$subsiteweb=$subsiteCtx.Web
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$ctx.Credentials = $credentials
$ctx.ExecuteQuery()
$pageLayoutList = $ctx.Web.Lists.GetByTitle("Master Page Gallery")
$ctx.Load($pageLayoutList)
$ctx.ExecuteQuery()
$pageLayoutQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
$pageLayoutQuery.ViewXml = "<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='Text'>"+$pageLayoutName+"</Value></Eq></Where></Query></View>"
$pageLayouts = $pageLayoutList.GetItems($pageLayoutQuery)
$ctx.Load($pageLayouts)
$ctx.ExecuteQuery()
$pageLayout = $pageLayouts[0]
Write-Host $pageLayouts.Count "-" $pageLayout.Id
#Get the publishing Web
$pubWeb = [Microsoft.SharePoint.Client.Publishing.PublishingWeb]::GetPublishingWeb($subsiteCtx, $subsiteCtx.Web)
$subsiteCtx.Load($pubWeb)
$subsiteCtx.ExecuteQuery()
$pageInfo = New-Object Microsoft.SharePoint.Client.Publishing.PublishingPageInformation
$pageInfo.Name = $pageName
$pageInfo.PageLayoutListItem = $pageLayout
$page = $pubWeb.AddPublishingPage($pageInfo)
$subsiteCtx.Load($page)
$subsiteCtx.ExecuteQuery()