I encountered an interesting issue in a new SharePoint 2010 farm that I built using content databases from an existing farm. The new farm was built because there had been an split of the company and half of the users moved to the new
company. So, the scenario was that they would continue to use their same AD credentials but use the new SharePoint farm that had been created with relevant content databases of the old farm. So far so good…
A user just forwarded an alert he received from the new farm, because he had subscribed for that alert in the old farm (say http://abc.com/LibraryA) and the content database was moved to the new one (say http://xyz.com/LibraryA). So, when someone uploaded a document, he received an alert and guess what? The mail was generated from the New farm, obviously, but was referring the URL of the content as http://abc.com/LibraryA/NewContent, the old one !!!
Now, from where the alert mail was getting the old URL?
I looked into the content database directly for all the users having any alerts subscription. For Immediate alerts subscription, the information gets stored in the table “ImmedSubscriptions“. There is a field in that table that stores the absolute URL of sites, wierd. The entries of this field don’t get updated if you restore the content database backup to a new farm where your web application URL is different. The end result of this – Users getting alerts from the new farm with the out of the box alert mails showing all the links pointing to old farm !!!
So, how to fix this? Obviously we can’t update the content database directly. So, here comes the PowerShell for rescue again..
There are 2 ways to do this –
Update the SiteURL property of the Alerts using Powershell and set that to the updated ones
$SPwebApp = Get-SPWebApplication “http://sites.mysharepoint.com”
foreach ($SPsite in $SPwebApp.Sites)
{
foreach($SPweb in $SPsite.AllWebs)
{
$alerts = $SPweb.Alerts
foreach($alert in $alerts)
{
try
{
$urlbeforeupdate = $alert.properties[“siteurl”]
if($alert.properties -ne $null)
{
if($alert.properties[“siteurl”] -ne $null)
{
$alert.properties[“siteUrl”] =”http://sites.mysharepoint.com”;
$alert.Update()
}
}
write-host -f Green $alert.Title
“User Name – ” + $alert.User.Name
“Title – ” + $alert.Title
“Frequency – ” + $alert.AlertFrequency
“Delivery Via – ” + $alert.DeliveryChannels
“Change Type – ” + $alert.eventtype
“URL before update – ” + $urlbeforeupdate
“URL after update – ” + $alert.properties[“siteurl”]
Write-Host “==================================”
}
catch
{
“Error”
}
}
}
}
}
Another approach that is similar and is my personal favorite is update any other property of the alert, like frequency and let SharePoint itself find out the correct SiteURL to use.
$SPwebApp = Get-SPWebApplication “http://sites.mysharepoint.com“
foreach ($SPsite in $SPwebApp.Sites)
{
foreach($SPweb in $SPsite.AllWebs)
{
$alerts = $SPweb.Alerts
foreach($alert in $alerts)
{
if($alert.AlertFrequency -eq [Microsoft.SharePoint.SPAlertFrequency]::Daily)
{
$alert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Immediate
$alert.Update()
$alert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Daily
$alert.Update()
}
ElseIf($alert.AlertFrequency -eq [Microsoft.SharePoint.SPAlertFrequency]::Immediate)
{
$alert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Daily
$alert.Update()
$alert.AlertFrequency =[Microsoft.SharePoint.SPAlertFrequency]::Immediate
$alert.Update()
}
Else
{
$alert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Daily
$alert.Update()
$alert.AlertFrequency =[Microsoft.SharePoint.SPAlertFrequency]::Weekly
$alert.Update()
}
write-host -f Green $alert.Title
“User Name – ” + $alert.User.Name
“Title – ” + $alert.Title
“Frequency – ” + $alert.AlertFrequency
“Delivery Via – ” + $alert.DeliveryChannels
“Change Type – ” + $alert.eventtype
Write-Host “==================================”
}
}
}
This script doesn’t actually change anything, it simply updates the frequency to some other value and sets it back to their original one. This will force alerts to update its stored absolute URLs and fix the issues reported regarding that.
Hope this helps, Enjoy !!!
1 comment
Wonderful post – I tried your preferred way and it worked like a charm!! Million thanks Anupam! Wasted days trying different suggestions before finding your post 🙁