Pages

25 October 2011

Migrated Alerts contains wrong URL

ISSUE DESCRIPTION:
In a context of a sharepoint 2007 Migration to SharePoint 2010, you have changed the URLs of your webapplication (example from http://portal.domain.com to http://sharepoint.domain.com)
Then the alerts received by the users contains the previous url in the links.

SOLUTION:
I have created an automated script that will verify the alerts properties for a SiteCollection, and another script that can update the URLs with the new created ones.

CheckAlertsUrlScript:

param (
        [string]$url = $(throw "Missing Site Collection URL (please use -url [sitecollectionUrl])")
      )
#Addin SharePoint2010 PowerShell Snapin
Add-PSSnapin -Name Microsoft.SharePoint.PowerShell

$webs = Get-SPweb -site $url -limit all
    foreach ($event in $webs)
    {
    $alerts = $event.alerts
        foreach ($event1 in $alerts)
        {
        write-host $event1.user $event1.properties["siteUrl"] $event1.properties["dispformurl"] -foregroundcolor green
        }
    }

Paste the above code in a PowerShellScript file, like [CheckAlertsUrl.ps1] and copy it on your local SharePoint Server Drive.

Launch the script from a Windows Powershell Cmd Prompt using the following parametters:
.\CheckAlertsUrl.ps1 -url <sitecollectionUrl>

UpdateAlertsUrlScript:
param (
        [string]$url = $(throw "Missing Site Collection URL (please use -url [sitecollectionUrl])"),
        [string]$newurl = $(throw "Missing New main URL (please use -newurl [MainUrl])")
      )
     
#Addin SharePoint2010 PowerShell Snapin
Add-PSSnapin -Name Microsoft.SharePoint.PowerShell

$webs = Get-SPweb -site $url -limit all
    foreach ($event in $webs)
    {
    $alerts = $event.alerts
   
        foreach ($event1 in $alerts)
        {
        write-host $event1.user $event1.properties["siteUrl"] $event1.properties["dispformurl"]
        $event1.properties["siteUrl"] = $newurl
        $event1.update()
        write-host "Alert has been updated successfully with correct URL" $event1.properties["siteUrl"] -foregroundcolor green
        }
    }
Paste the above code in a PowerShellScript file, like [UpdateAlertsUrl.ps1] and copy it on your local SharePoint Server Drive.

Launch the script from a Windows Powershell Cmd Prompt using the following parametters:
.\UpdateAlertsUrl.ps1 -url <sitecollectionUrl> -newurl <NewMainUrl>

0 comments:

Post a Comment