PowerShell: SharePoint - Change URL Used in an Alert

Updated on 2/19/2015
[void] [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[void] [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[void] [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search")

function ChangeAlertUrl($pWeb)
{
	$title = $pWeb.Title
	Write-Host "Processing web: $title "
	foreach($alert in $pWeb.Alerts)
	{
		$siteurl = $alert.Properties["siteurl"]
		$atitle = $alert.title
		Write-host "Changing alert '$atitle' from $siteurl to $newAlertUrl"
		$alert.Properties["siteurl"] = $newAlertUrl	
		$alert.Update()
	}
	
	Write-Host "-------------------"

	foreach($subweb in $pWeb.Webs)
	{
	    ChangeAlertUrl($subweb)
	}
}

$newAlertUrl = "https://correctAlertUrl"
$site = New-Object Microsoft.SharePoint.SPSite("https://sharepoint/")
ChangeAlertUrl($site.RootWeb)