i'm quite new to using powershell and sharepoint, and i've been running into issues creating a new page on a subsite. I've been trying to follow code i found here:
https://sharepointstew.wordpress.com/2015/03/09/csom-powershell-to-create-a-sharepoint-publishing-page-with-custom-or-oob-page-layout/
and here: https://www.sharepointdiary.com/2018/04/sharepoint-online-create-publishing-page-using-powershell.html
I think the issue is that it's trying to find blankwebpart.aspx in the master page gallery in my subsite, however checking there i have no blankwebpart.aspx files there or in the root web master page gallery. I've also tried running it on my rootweb with DefaultLayout.aspx but still same issues. I'm kind of at a loss for how to proceed, here's some of the errors i'm running into:
function returnThings($Context) {
$List = $Context.Web.Lists
$Context.load($List)
$Context.executeQuery()
$mpList = $List.GetByTitle("Master Page Gallery")
$PageLayoutName = "DefaultLayout.aspx"
$camlQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
$camlQuery.ViewXml = '<View><Query><Where><Eq><FieldRef Name="FileLeafRef" /><Value Type="Text">' + $PageLayoutName + '</Value></Eq></Where></Query></View>'
$items = $mpList.GetItems($camlQuery)
$Context.Load($items)
$Context.ExecuteQuery()
$pageLayoutItem = $items[0]
$Context.Load($pageLayoutItem)
foreach ($PageL in $items) {
write-host "See below: " -ForegroundColor Blue
$PageL | ConvertTo-Csv
}
# Get publishing web object
#
$web = $Context.Web
$pubWeb = [Microsoft.SharePoint.Client.Publishing.PublishingWeb]::GetPublishingWeb($Context, $web)
$Context.Load($pubWeb)
#Get pages library.
$pagesList = $Context.Web.Lists.GetByTitle("Pages")
$PageName = "Project Deviations"
$pubPageInfo = New-Object Microsoft.SharePoint.Client.Publishing.PublishingPageInformation
$pubPageInfo.Name = $PageName.Replace(" ", "-") + ".aspx"
$pubPageInfo.PageLayoutListItem = $pageLayoutItem
$pubPage = $pubWeb.AddPublishingpage($pubPageInfo)
$pubPage.ListItem.File.CheckIn("", [Microsoft.SharePoint.Client.CheckinType]::MajorCheckIn)
$pubPage.ListItem.File.Publish("")
$pubPage.ListItem.File.Approve("")
$Context.Load($pubPage)
$Context.ExecuteQuery()
}
Exception calling "ExecuteQuery" with "0" argument(s): "List 'Pages' does not exist at site with URL
'https://companydemo2.sharepoint.com/sites/TEAM'."
At C:\Users\conormo\Documents\Sharepoint Repos\KcentralMigration\Scripts\testProjDeviations.ps1:70 char:5
+ $Context.ExecuteQuery()
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ServerException
I'm using the sharepoint online management shell and have the sharepoint dll's installed and all. I'm sure i'm missing something plainly obvious here, cheers