Skip to content

Instantly share code, notes, and snippets.

@nlarkin
Created March 1, 2013 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nlarkin/5067607 to your computer and use it in GitHub Desktop.
Save nlarkin/5067607 to your computer and use it in GitHub Desktop.
This is a powershell script that will update all the times for alerts within a specified Sharepoint Site. You must change the url and time to match your needs.
cls
$error.Clear()
##################################################################################################
# Load SharePoint Snapin
##################################################################################################
$snap = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snap -eq $null) {
Write-Host "Loading Powershell Snapin..." -ForegroundColor Yellow
Add-PSSnapin Microsoft.SharePoint.Powershell
}
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-Null
##################################################################################################
# Global Variables
##################################################################################################
$Today = [string]::Format( "{0:yyyy-MM-dd}", [datetime]::Now.Date )
###Configuration###
$SiteCollectionUrl = "Enter Site URL Here"
$NewAlertTime = "2/26/2013 4:00:00 PM"
$RootWeb = get-spweb $SiteCollectionUrl
$TranscriptFileName = "$Today - List User Alerts.txt"
$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Write-Host "Starting Transcript..." -ForegroundColor Yellow
Start-Transcript -path $TranscriptFileName
Write-Host "##########################################################################################" -ForegroundColor Yellow
Write-Host "# $Today - Running User Alerts Script" -ForegroundColor Yellow
Write-Host "# Script will update date/time that alerts will be distributed." -ForegroundColor Yellow
Write-Host "##########################################################################################" -ForegroundColor Yellow
Write-Host ""
##################################################################################################
# Loop through sites
##################################################################################################
foreach ($web in $RootWeb.Webs)
{
Write-Host “==================================” -ForegroundColor Green
Write-Host ("Updating alerts for site: "+$web.Title)
Write-Host “==================================” -ForegroundColor Green
foreach($alert in $web.Alerts)
{
Write-Host “Updating alert :” $alert.title -ForegroundColor Yellow
write-host “Subscribed User: ” $alert.user
$alert.AlertTime = $NewAlertTime
write-host “Alert updated to: ” $alert.AlertTime
}
Write-Host “==================================” -ForegroundColor Green
Write-Host ("Done updating alerts for:"+$web.Title)
Write-Host “==================================” -ForegroundColor Green
}
#end
Write-Host "Script Completed....`n`n" -ForegroundColor Yellow
Stop-Transcript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment