Saturday, October 15, 2011

Update Wrong Old URL in SharePoint Alerts on SharePoint Migration or URL Change

After upgrading from MOSS 2007 to SharePoint 2010, existing SharePoint alerts stopped working and only newly created alerts worked!!! We got to Fix Alerts after SharePoint migration, manually.

Tried these trial and errors:

  • Tried editing existing alerts, just changed its Name, It worked!
  • Tried Turning Individual Alert ON and OFF - Yes, Worked! but I've some 1000+ alerts for a Large web application. How about PowerShell?

$SPSite= Get-SPSite "http://mySharePoint.com/sites/alerts/"

foreach ($spweb in $SPSite.AllWebs)
    {
        foreach($alert in $spweb.Alerts)
            {
                $OriginalTitle = $alert.Title
                $alert.Title = "UPDATE: $OriginalTitle"
                $alert.Update()

                $alert.Title = $OriginalTitle
                $alert.Update()
                Write-Host "Updated Alert" $alert.Title "in"$spweb.url

            }
    }
But wait, the problem is not fully solved. From the Alert mails fired from the alerts created in MOSS 2007, URLs in the Alert mail is still pointing to OLD URL!
sharepoint 2010 email alerts wrong url

Fix SharePoint alerts wrong URL Issue:
Again, Powershell is a life saver. Use this script to Fix the wrong URLs in alerts and to fix the issue of "Old Alerts are not firing"

$SPSiteURL = "http://NewSharePoint.com/sites/alerts" #Site Collection Url 
$oldrooturl = "https://OldSharePoint.crescent.com" # Old URL of the webapplication
$rooturl = "http://NewSharePoint.com" # New URl for the new webapplication

$SPsite = Get-SPSite -Identity $SPSiteURL 
$SPwebs = $SPsite.AllWebs 

$updated = 0

foreach ($web in $SPwebs) #Get All the sub sites
{
  $alerts = $web.alerts  # Get All Alerts

  if ($alerts.count -ne 0)
   {    
   Write-Host -foregroundcolor green "Number of Alerts in: "$web.url ":" $alerts.count
   
    foreach ($alert in $alerts)
    {
  #preserve & Change the the Alert frequency, so that the so the datarow inside is touched by SharePoint API. 
  $Status = $alert.Status 
                $Frequency = $alert.AlertFrequency
                    if($Frequency -eq [Microsoft.SharePoint.SPAlertFrequency]::Immediate)
                     { 
                         $alert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Weekly 
                     } 
                    else
                      { 
                         $alert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Immediate 
                      } 
   
   $title = $alert.title
          $alert.title = "UPDATED" + $title
          $alert.Status = [Microsoft.SharePoint.SPAlertStatus]::Off 

             $alert.Update()  #Update the modified values
             
       if ($alert.Properties -ne $null)
        {
          if ($alert.Properties["siteurl"] -ne $null -and $alert.Properties["siteurl"].Contains($oldrooturl))
           {
             $alert.Properties["siteurl"] = $alert.Properties["siteurl"].Replace($oldrooturl, $rooturl)
           }
           if ($alert.Properties["mobileurl"] -ne $null -and $alert.Properties["mobileurl"].Contains($oldrooturl))
           {
             $alert.Properties["mobileurl"] = $alert.Properties["mobileurl"].Replace($oldrooturl, $rooturl)
           }

          $updated++

         }


 #Reset the Values of alert, back to their original
      $alert.title = $title
             $alert.AlertFrequency = $Frequency 
      $alert.Status = $Status 
             $alert.Update()    

  write-host "Alert updated: " $title
        #$alert.Properties

    }
    Write-Host "Number of alerts updated: " $updated
  }
}

Not only during Migration, But this will help during changing the SharePoint URL also! Once you get a list of locations, Just Turn-Off and Turn-On the Incoming E-Mails settings of the Library.

Microsoft KB Addressing this issue: http://support.microsoft.com/kb/936760

In MOSS 2007, after moving to new URL you can simply run the "stsadm -o updatealert" command to update the alert mail's URLs.

Lately, Microsoft released a Custom Cmd-let Invoke-AlertFixup which is equivalent of UpdateAlert operation. here is the link: http://technet.microsoft.com/en-us/library/cc508847.aspx



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

4 comments :

  1. Nice post…keep your work up..i will visit ur site regularly..good work.discover pleasant and valuable information.

    Showing your skills set and good stuff.

    ReplyDelete
  2. Hi Salaudeen,
    I've applied the above 1st script (line 1-16) to update Alert Title but still not getting alerts for existing alerts (the ones migrated from 2007). However newly created (in 2010) alerts are working.

    When I looked at the [ImmedSubscriptions] table, I found SiteURL was still showing the old web app. I tried few other scripts but nothing seems to get my existing alerts working. Until I ran Update command directly (per below link) into the table to change the SiteURL to my new web app URL. Alerts are not working but I know it's not supported way. Do you have any suggestion why SiteURL not updating even after I'm running your first script?

    Thank you in advanced for any suggestion!

    http://trycatch.be/blogs/tom/archive/2008/05/12/alerts-don-t-work-after-url-change.aspx

    ReplyDelete
  3. Great buddy u have save my time and effort................Go for it guys!!!!!!!

    ReplyDelete
  4. Really good information friend. Thanks for the post.

    ReplyDelete

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...