我需要在某些网站的主页上添加ContentEditorWebPart
。我正在使用powershell
脚本来执行此操作。
WebPart正在添加到页面中,我能够看到它,但是如果我尝试编辑它,我将无法看到添加的WebPart。在WebPart页面上,一切正常。
Add-PSSnapin microsoft.sharepoint.powershell
# function to set the content editor webpart
function SetContentEditorWebPart($path)
{
# get contents from csv file
$csvcontents=Import-Csv -Path $path
foreach($site in $csvContents)
{
#iterate through each site and add content editor webpart on the home page of the site
$url=$site.'Site Url'
$website=Get-SPSite -Identity $url
$web=$website.RootWeb
$wpmgr=$web.GetLimitedWebPartManager($web.RootFolder.WelcomePage,[system.web.ui.webcontrols.webparts.personalizationscope]::Shared)
$contenteditorwebpart=New-Object microsoft.sharepoint.webpartpages.ContentEditorWebPart
$contenteditorwebpart.Title="Site Migration Information"
$contenteditorwebpart.ChromeType=[system.web.ui.webcontrols.webparts.PartChromeType]::TitleAndBorder
[system.Xml.XmlDocument]$content=New-Object system.Xml.XmlDocument
[system.Xml.XmlElement]$contentxml=$content.CreateElement("MigrationContent")
$contentxml.InnerText="Your SharePoint site is ready!"+" "+"<a href="+$site.Test+">Here</a>"+" "+"is the link for the New site"
$contenteditorwebpart.Content=$contentxml
$wpmgr.AddWebPart($contenteditorwebpart,"Body",1)
$wpmgr.SaveChanges($contenteditorwebpart)
}
}
# Provide the path of Csv File containing site urls and call the function
SetContentEditorWebPart("Path for the Csv File")