Today, I would like to share my knowledge on the recently concluded SharePoint migration project in our company.
After the migration of sites, we were asked by our client to put a banner on the old sites so when the members access the site, they will see the banner and upon clicking the banner, they would be redirected to the newly migrated site.
The real problem with this task was that we had only two members in the team and the total number of sites migrated was around 65. So, we had to literally go to all the sites and put the banner as Content Editor web part on the homepage of each site.
We thought of writing a PowerShell script which will add banner as Content Editor web part on all the old sites. Here are steps involved in the process.
- Prepare the CSV file which contains two columns, namely “Site URL,” which will have all the old site urls for which we need to add banner, and “New Site” which will have all the new site URLs which is the redirection URL on the corresponding old site.
- Execute the script (which was done by SharePoint admin)
- After successful execution of the script, verify whether the banner has been added or not, and check the redirection URL.
- 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 has migrated to O365!" + " " + "<a href=" + $site.
- 'New Site' + ">Here</a>" + " " + "is the link for the O365 site.Please use email address to log in but no password should be needed."
- $contenteditorwebpart.Content = $contentxml
- $wpmgr.AddWebPart($contenteditorwebpart, "Header", 1)
- $wpmgr.SaveChanges($contenteditorwebpart)
- }
- }#Provide the path of Csv File containing site urls and call the
- function
- SetContentEditorWebPart("Path for the CSV File")
NehaPosted Jan 5, 2017, 5:36 AM
Nice one.............................................