I was moving a site from production to development today and was welcomed to my new site with the following lovely message from SharePoint:

image

(The Web application at http://intranetprod/RA could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.)

So, if you have ever moved a calendar from one place to another, either as part of a site move or a list move, you will be greeted by the fact that your calendar overlays no longer work because the URLs to the overlaying calendars are hardcoded into the list view.  This calendar had 3 overlays and there are other calendars with more overlays.  I am trying to set up an automated restore from production to development, so having lots of broken calendars isn’t great.  Fortunately, all you have to do is run a few lines of PowerShell to fix this. 

I’ll walk you through the steps, the full code is below.

  1. Connect to the web in question.  You could very easily have this step through all webs in a site collection to update all your lists at once.
  2. Get your list.  Again, this could easily get all lists and look for calendars to update
  3. Get your view.  This assumes your view is called “Calendar” which is the default.  You could update it to be whatever your view is called.
  4. Get the CalendarSettings property of the view.  This is where the links are stored for the overlay.
  5. Then, just use the PowerShell replace command to replace your old URL with the new one.
  6. Apply the changes back to the property and update the view to save changes.

So, here is the full script.  Hope this helps.

   1:  #Add SharePoint PowerShell SnapIn if not already added 
   2:  if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) { 
   3:      Add-PSSnapin "Microsoft.SharePoint.PowerShell" 
   4:  }
   5:   
   6:  $web = Get-SPWeb “http://intranetdev” 
   7:  $mainCalendar = $web.Lists["Calendar"] 
   8:  $view = $mainCalendar.Views["Calendar"]
   9:   
  10:  $calSettings = $view.CalendarSettings 
  11:  $view.CalendarSettings = $calSettings.Replace("intranetprod", "intranetdev") 
  12:  $view.Update()