0

I am trying to migrate Announcements from Sharepoint 2013 into Sharepoint Online News Webpart.

I can get the old Announcements into a Excel file(CSV) with an simple export for the List in Sharepoint 2013. I need to import these into Sharepiont Online as Site Pages that are then promoted to News items.

I have a few powershell commands that i think can accomplish this but i am having trouble putting it all together. I am new to Sharepoint.

I found this code to create site pages

#Config Variable
$SiteURL = "https://crescent.sharepoint.com/sites/Intranet"
  
#Connect to PpP Online
Connect-PnPOnline -Url $SiteURL -Interactive # -Credentials (Get-Credential)
  
#Create new page
$Page = Add-PnPPage -Name "News" -LayoutType Article
 
#Set Page properties
Set-PnPPage -Identity $Page -Title "News" -CommentsEnabled:$False -HeaderType Default
 
#Add Section to the Page
Add-PnPPageSection -Page $Page -SectionTemplate OneColumn
 
#Add Text to Page
Add-PnPPageTextPart -Page $Page -Text "Welcome To News Portal" -Section 1 -Column 1

#Publish the page
$Page.Publish()

This code can be used to Promote it as a News item

$SiteURL = "https://crescent.sharepoint.com/sites/Intranet"
 
#Connect to Site
Connect-PnPOnline $SiteURL -Interactive
 
#Get all Site pages - along with their IDs
Get-PnPListItem -List "SitePages"
 
#Demote News page with ID "4" to Site Page
Set-PnPListItem -List "SitePages" -Values @{"PromotedState"="2"}

How do i combine all this so that i can create News Site Pages from the CSV?

Thanks

2 Answers 2

0

You can use Import-Csv to get site page properties in csv. Please refer to following code.

$PageNames = Import-Csv -Path c:\temp\test.csv
foreach($PageName in $PageNames){
   ...
}
1
  • Have you tried the solution I proposed? If you have any questions or progress, you can contact me in time. Looking forward to your reply Have a lucky day! Thanks, Raytheon Xie Apr 26, 2022 at 1:21
0

Building on Raytheon-Xie-MSFT answer, the code would look like this (if you can provide an example of the CSV file - what metadata you need to write, this can be refined to exactly write out the pages:

Add-Type -AssemblyName System.Windows.Forms

# Ask the user for the Page input file 
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog
$null = $FileBrowser.ShowDialog()

$page_file_name = $FileBrowser.FileNames

if ( !$page_file_name){
    Write-Host 'No input file was selected, terminating script'
    exit # nothing to see here, an input file was not selected
}

$SiteURL = "https://crescent.sharepoint.com/sites/Intranet"
  
#Connect to PpP Online
Connect-PnPOnline -Url $SiteURL -Interactive

# note: better to us tab delimited files since page names can include commas
$Pages= Import-Csv -Path $page_file_name

foreach($Page in $Pages){
 #Create new page
$Page = Add-PnPPage -Name "News" -LayoutType Article
 
#Set Page properties
Set-PnPPage -Identity $Page -Title "News" -CommentsEnabled:$False -HeaderType Default
 
#Add Section to the Page
Add-PnPPageSection -Page $Page -SectionTemplate OneColumn
 
#Add Text to Page
Add-PnPPageTextPart -Page $Page -Text "Welcome To News Portal" -Section 1 -Column 1

#Publish the page
$Page.Publish()
}

Get-PnPListItem -List "SitePages"
 
#Demote News page with ID "4" to Site Page
Set-PnPListItem -List "SitePages" -Values @{"PromotedState"="2"}

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.