*** UPDATE 12/31/2017: This Project Was Migrated From CodePlex to Github ***
Releases:
- Version 2: (Stable) [ Nov 28 2011]
- Version 1 (Stable) [ Mar 28 2011]
*** UPDATE 12/31/2017: This Project Was Migrated From CodePlex to Github ***
$oldrooturl = "https://<url>"
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")> $null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Portal")> $null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Security")> $null
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local;
$services = @($farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]})
foreach ($service in $services)
{
foreach($app in $service.WebApplications)
{
$sites = $app.Sites
if ($app.DisplayName.Contains('Central Administration'))
{
continue
}
foreach ($site in $sites)
{
if (!$site.ServerRelativeUrl.Contains("ssp/") -and !$site.ServerRelativeUrl.Contains("MySite"))
{
$rooturl = $site.Url.Replace($site.ServerRelativeUrl, '')
foreach ($web in $site.AllWebs)
{
$updated = 0
$alerts = $web.alerts
Write-Host "Number of Alerts in: "$web.url ":" $alerts.count
if ($alerts.count -ne 0)
{
foreach ($alert in $alerts)
{
$alert.Status = [Microsoft.SharePoint.SPAlertStatus]::Off
$alert.Update()
if ($alert.Properties -ne $null)
{
$changed = $FALSE
$siteUrl = $alert.Properties["siteurl"]
if ($siteUrl -ne $null -and $siteUrl.Contains($oldrooturl))
{
$alert.Properties["siteurl"] = $siteUrl.Replace($oldrooturl, $rooturl)
$changed = $TRUE
}
$mobileUrl = $alert.Properties["mobileurl"]
if ($mobileUrl -ne $null -and $mobileUrl.Contains($oldrooturl))
{
$alert.Properties["mobileurl"] = $mobileUrl.Replace($oldrooturl, $rooturl)
$changed = $TRUE
}
if ($changed)
{
$updated++
write-host "Alert updated: " $alert.Title "For User: " $alert.User
}
}
$alert.Status = [Microsoft.SharePoint.SPAlertStatus]::On
$alert.Update()
}
Write-Host "Number of alerts updated: " $updated
}
}
}
$site.Dispose()
}
}
}
#Load assemblies
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")> $null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Portal")> $null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Security")> $null
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local;
$services = @($farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]})
foreach ($service in $services)
{
foreach($app in $service.WebApplications)
{
$sites = $app.Sites
foreach ($site in $sites)
{
if (!$site.ServerRelativeUrl.Contains("ssp/"))
{
foreach ($currentWeb in $site.AllWebs)
{
$pages = $currentWeb.Files | Where-Object {$_.Name -match ".aspx"}
Write-Host "Analyzing Web $($currentWeb.Url)."
foreach($currentPage in $pages)
{
Write-Host "Analyzing Page $($currentPage.ServerRelativeUrl)."
if ($currentPage.CheckedOutByUser -ne $NULL)
{
$currentPage.CheckIn("Administratively Checked-In");
}
$url = $currentPage.ServerRelativeUrl;
if ($url -eq $NULL)
{
continue
}
$webPartManager = $currentWeb.GetLimitedWebPartManager($url, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
$closedWebparts = New-Object System.Collections.ArrayList
$badWebparts = New-Object System.Collections.ArrayList
foreach($webpart in $webPartManager.WebParts)
{
if($webpart.IsClosed)
{
$closedWebparts.add($webpart);
}
elseif ($webpart.FatalError)
{
$badWebparts.add($webPart)
}
else
{
$webPart.AllowClose = $FALSE;
$webPart.AllowZoneChange = $TRUE;
}
}
foreach($webpart in $closedWebparts)
{
Write-Host "Deleting closed webpart $($webpart.Title) on page $($currentPage.ServerRelativeUrl)."
$webPartManager.DeleteWebPart($webpart);
}
foreach($webpart in $badWebparts)
{
Write-Host "$($webpart.ID) on $($currentPage.ServerRelativeUrl) is reporting $($webpart.ImportErrorMessage) "
#$webPartManager.DeleteWebPart($webpart);
}
}
$currentWeb.Dispose()
}
}
$site.Dispose()
}
}
}