Forum Discussion
Fromelard
Oct 10, 2018Iron Contributor
How to create Repost Page (Modern Page Library) with PowerShell
Dear all,
I tried to create a PowerShell script to create automatically "Modern Repost Page" pointing to the news page published into the SharePoint Publishing site (Global Intranet Site).
Th...
- Oct 12, 2018
Dear all,
I finally found how to do the Repost Page Creation with CSOM only.
The missing parts were the page layout to load correctly the page in edit mode, the PromotedState to be sure it will be considered as a news and the last ID to know exactly the target:
- ["_OriginalSourceSiteId"]
- ["_OriginalSourceWebId"]
- ["_OriginalSourceListId"]
- ["_OriginalSourceItemId"]
The code has to be similar to the following one:
$NewPageitem["ContentTypeId"] = "0x0101009D1CB255DA76424F860D91F20E6C4118002A50BFCFB7614729B56886FADA02339B00874A802FBA36B64BAB7A47514EAAB232"; $NewPageitem["PageLayoutType"] = "RepostPage" $NewPageitem["PromotedState"] = "2" $NewPageitem["Title"] = $CSVItem.NewsTitle $NewPageitem["ClientSideApplicationId"] = "b6917cb1-93a0-4b97-a84d-7cf49975d4ec" $NewPageitem["_OriginalSourceSiteId"] = $MyDestinationPageSiteColl.ID $NewPageitem["_OriginalSourceWebId"] = $MyDestinationPageweb.ID $NewPageitem["_OriginalSourceListId"] = $MyDestinationPagelist.ID $NewPageitem["_OriginalSourceItemId"] = $MyDestinationPageFileitem["UniqueId"].ToString() $NewPageitem["_OriginalSourceUrl"] = $MyCSVNewsURL $NewPageitem["Editor"] = $MyEditoruserAccount.Id $NewPageitem["Author"] = $MyEditoruserAccount.Id $NewPageitem["Description"] = $MyCSVNewsDescription $NewPageitem["BannerImageUrl"] = $MyCSVNewsPictureURL; $NewPageitem["Modified"] = $MyCSVPublishingDate; $NewPageitem["Created"] = $MyCSVPublishingDate; $NewPageitem["Created_x0020_By"] = $MyEditoruserAccount.LoginName $NewPageitem["Modified_x0020_By"] = $MyEditoruserAccount.LoginName $NewPageitem["FirstPublishedDate"] = $MyCSVPublishingDate; $NewPageitem.Update(); $MyctxTemp.Load($NewPageitem); $MyctxTemp.ExecuteQuery();
It's now working perfectly and the only point i'm fighting with is the picture display.
Thanks a lot for your help
Fab
João Miguel
Mar 21, 2022Copper Contributor
There is a API to create repost pages:
_api/sitepages/pages/reposts
You can use it like this:
Invoke-PnPSPRestMethod -Url https://Contoso.sharepoint.com/sites/SiteName/_api/sitepages/pages/reposts -Method Post -Content @{ Title = "Repost Title"; OriginalSourceUrl = "https://www.RedirectUrl.com"; Description = "Description Text" }
The accepted parameters are:
BannerImageUrl: "https://some.absolute/path/to/an/image.jpg",
IsBannerImageUrlExternal: true,
Description: "My Description",
Title: "This is my title!",
OriginalSourceUrl: "https://absolute/path/to/article"
OriginalSourceItemId : 00000000-0000-0000-0000-000000000000
OriginalSourceListId : 00000000-0000-0000-0000-000000000000
OriginalSourceSiteId : 00000000-0000-0000-0000-000000000000
OriginalSourceWebId : 00000000-0000-0000-0000-000000000000
Making a Get to this API it will return the existing news.
I'm not sure but I don't think adding it using the suggested method on this post makes it appear the replys of this API.
_api/sitepages/pages/reposts
You can use it like this:
Invoke-PnPSPRestMethod -Url https://Contoso.sharepoint.com/sites/SiteName/_api/sitepages/pages/reposts -Method Post -Content @{ Title = "Repost Title"; OriginalSourceUrl = "https://www.RedirectUrl.com"; Description = "Description Text" }
The accepted parameters are:
BannerImageUrl: "https://some.absolute/path/to/an/image.jpg",
IsBannerImageUrlExternal: true,
Description: "My Description",
Title: "This is my title!",
OriginalSourceUrl: "https://absolute/path/to/article"
OriginalSourceItemId : 00000000-0000-0000-0000-000000000000
OriginalSourceListId : 00000000-0000-0000-0000-000000000000
OriginalSourceSiteId : 00000000-0000-0000-0000-000000000000
OriginalSourceWebId : 00000000-0000-0000-0000-000000000000
Making a Get to this API it will return the existing news.
I'm not sure but I don't think adding it using the suggested method on this post makes it appear the replys of this API.