How to Operate SharePoint User Alerts with PowerShell

When you migrate list or site, the user alerts in the site will not be migrated together with the content. Below content can help you to do this task. But please take care of it, if you operate it on Prod environment.

Enable or disable alerts for Web application

## To enable alerts for Web application

$SPwebapp=Get-SPWebApplication "http://SharePointSite.com"

$SPwebapp.AlertsEnabled = $true

$SPwebapp.Update()

# To Disable alerts for a Web application

$SPwebapp.AlertsEnabled = $false

$SPwebapp.Update()

Create Alert in SharePoint using PowerShell

##### Create an New alert for an user #########

$SPsite = Get-SPSite "http://SharePointSite.com"

$SPweb=$SPsite.Rootweb

$SPlist=$SPweb.lists["Shared documents"]

$SPuser = $SPweb.EnsureUser(‘Domain\Salaudeen‘)

$SPnewAlert = $SPuser.Alerts.Add()

$SPnewAlert.Title = "My Custom Alert"

$SPnewAlert.AlertType=[Microsoft.SharePoint.SPAlertType]::List

$SPnewAlert.List = $SPlist

$SPnewAlert.DeliveryChannels = [Microsoft.SharePoint.SPAlertDeliveryChannels]::Email

$SPnewAlert.EventType = [Microsoft.SharePoint.SPEventType]::Add

$SPnewAlert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Immediate

$SPnewAlert.Update()

$SPweb.Dispose()

$SPSite.Dispose()

Get all Alerts for an user in SharePoint with PowerShell

##### Display All alerts for a Particular List ########

$SPWeb = Get-SPWeb "http://SharePointSite.com"

#Relative URL of list/document library. For lists "Lists/Tasks"

$SPListURL = "Shared Documents" 

foreach($alert in $SPWeb.Alerts)

{

    if($alert.ListUrl -eq $SPListUrl)

    {           

            "User Name    - " + $alert.User.Name

            "Title        - " + $alert.Title

            "Frequency    - " + $alert.AlertFrequency

            "Delivery Via - " + $alert.DeliveryChannels

            "Change Type  - " + $alert.eventtype

            Write-Host "=================================="

    }

}

$SPweb.Dispose()

Create Alerts for All users in a Group

##### Set alerts for all users in the SharePoint Group ######

$SPweb = Get-SPWeb "http://SharePointSite.com"

$SPgroup = $SPweb.Groups["SharePoint Owners"]

$SPlist = $SPweb.Lists["Shared Documents"]

foreach ($SPuser in $SPgroup.Users){

     $alert = $SPuser.Alerts.Add()

     $alert.Title = "My Alert"

     $alert.AlertType = [Microsoft.SharePoint.SPAlertType]::List

     $alert.List = $SPlist

     $alert.DeliveryChannels = [Microsoft.SharePoint.SPAlertDeliveryChannels]::Email

     $alert.EventType = [Microsoft.SharePoint.SPEventType]::Add

     $alert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Immediate

     $alert.Update()

}

$SPweb.Dispose()

Update SharePoint Alerts using PowerShell

#####  Making Changes in Existing Alerts ########

$SPsite = Get-SPSite "http://SharePointSite.com"

$SPweb=$SPsite.RootWeb

$SPuser=$SPweb.EnsureUser(‘Domain\Salaudeen‘)

$SPalertCollection=$SPuser.Alerts

foreach($alert in $SPalertCollection)

{

  $alert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Daily

  $alert.Update()

} 

Get Alerts for a Particular User

##### Get alerts for a particular user #########

$SPsite = Get-SPSite "http://SharePointSite.com"

$SPweb=$SPsite.RootWeb

$SPuser=$SPweb.EnsureUser(‘Domain\Salaudeen‘)

$SPalertCollection=$SPuser.Alerts

foreach($alert in $SPalertCollection)

{

 write-host -f Green $alert.Title

}

Find All Alerts of an User in Entire Site collection

##### Get the Alerts of Entire Site collection #####

$SPsiteCollection = Get-SPSite "http://SharePointSite.com"

# Iterate through all Webs in the Site Collection

foreach($SPweb in $SPsiteCollection.AllWebs) 

 {

   foreach($alert in $SPweb.Alerts)

    {

        Write-Host "Alerts List :" $alert.ListUrl

    Write-Host "Alerts Title :" $alert.title

    write-host "Subscribed User: " $alert.user

     }

 }

Delete All SharePoint alerts from a List using powershell

##### Delete All alerts for a specific List #####

$SPweb = Get-SPWeb "http://SharePointSite.com"

$SPlist = $SPweb.lists["Shared Documents"]

$IDS = ""

foreach($alert in $spweb.alerts)

{

    if($alert.ListID -eq $SPlist.ID)

    {

    $IDS += $alert.ID.tostring() + "|"

    }

    write-host -nonewline "*"

}

write-host "deleting..."

foreach($s in $IDS.Split("|"))

{

write-host -nonewline "*"

$spweb.alerts.delete([GUID]$s)

}

Delete user alerts in SharePoint 2010 with PowerShell

##### Remove all alerts for specific user from a Web Application #####

$SPwebApp = Get-SPWebApplication "http://SharePointSite.com"

$SpecificUser = "Domain\Salaudeen"

foreach ($SPsite in $SPwebApp.Sites)

    {

        # get the collection of webs

        foreach($SPweb in $SPsite.AllWebs)

        {

            $alerts = $SPweb.Alerts

            # if 1 or more alerts for a particular user, Make a note of them by copying their ID to an Array

            if ($alerts.Count -gt 0)

            {

                $myalerts = @()

                foreach ($alert in $alerts)

                {

                if ($alert.User -like $SpecificUser)

                {

                    $myalerts += $alert

                }

            }

            ### now we have alerts for this site, we can delete them

            foreach ($alertdel in $myalerts)

            {

                $alerts.Delete($alertdel.ID)

                write-host $alertdel.ID

            }

        }

    }

}

To delete all alerts:

$SPweb.Alerts| foreach-object {$web.Alerts.Delete($_.Id)}

Filter the alerts for a single list:

#For for e.g. http://SharePoint.com/site/Assets"
$SPweb.Alerts| where-object {$_.ListUrl -like "Assets"} 

Find all the Alerts for a specific user across the web:

# ? is the alias for where-object cmdlet
$web.Alerts | ? {$_.UserId -like "Domain\Salaudeen"}

Get all the alerts for a user across the entire site collection:

$site.AllWebs | select -expand Alerts | ? {$_.UserId -like "Domain\Salaudeen"

Export User Alerts

$site = Get-SPSite "http://2013portal"

$alertResultsCollection = @()

foreach ($web in $site.AllWebs) {

foreach ($alert in $web.Alerts){

$alertURL = $web.URL + "/" + $alert.ListUrl

$alertResult = New-Object PSObject

$alertResult |Add-Member -type NoteProperty -name "WebUrl" -Value $web.Url

$alertResult | Add-Member -type NoteProperty -name "ListURL" -value $alertURL

$alertResult | Add-Member -type NoteProperty -name "AlertTitle" -value $alert.Title

$alertResult | Add-Member -type NoteProperty -name "ListUrl" -value $alert.ListUrl

$alertResult | Add-Member -type NoteProperty -name "List" -value $alert.List

$alertResult | Add-Member -type NoteProperty -name "DeliveryChannel" -value $alert.DeliveryChannels

$alertResult | Add-Member -type NoteProperty -name "AlertType" -value $alert.AlertType

$alertResult | Add-Member -type NoteProperty -name "EventType" -value $alert.EventType

$alertResult | Add-Member -type NoteProperty -name "Frequency" -value $alert.AlertFrequency

$alertResult | Add-Member -type NoteProperty -name "AlertTime" -value $alert.AlertTime

$alertResult | Add-Member -type NoteProperty -name "SubscribedUser" -value $alert.User

$alertResultsCollection += $alertResult

}

}

$site.Dispose()

$alertResultsCollection

#Export to CSV

$alertResultsCollection | Export-CSV C:\Users\sp2013_farm_admin\Desktop\Alerts.csv

Import User Alerts

Import-Csv C:\Users\sp2013_farm_admin\Desktop\Alerts.csv |ForEach-Object{

$webUrl=$_.WebUrl

$listTitle=$_.List

$alertTitle=$_.AlertTitle

$subscribedUser=$_.SubscribedUser

$alertType=$_.AlertType

$deliveryChannel=$_.DeliveryChannel

$eventType=$_.EventType

$frequency=$_.Frequency

$web=Get-SPWeb $webUrl

$list=$web.Lists.TryGetList($listTitle)

$user = $web.EnsureUser($subscribedUser)

$newAlert = $user.Alerts.Add()

$newAlert.Title = $alertTitle

$newAlert.AlertType=[Microsoft.SharePoint.SPAlertType]::$alertType

$newAlert.List = $list

$newAlert.DeliveryChannels = [Microsoft.SharePoint.SPAlertDeliveryChannels]::$deliveryChannel

$newAlert.EventType = [Microsoft.SharePoint.SPEventType]::$eventType

$newAlert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::$frequency

if($frequency -ne "Immediate"){

$AlertTime=$_.AlertTime

$newAlert.AlertTime=$AlertTime

}

$newAlert.Update()

} 
时间: 2024-08-10 15:00:48

How to Operate SharePoint User Alerts with PowerShell的相关文章

sharepoint 2013:活动目录迁移用户后,在sharepoint中move 用户 powershell

Get-SPUser -web http://wfe1  | fl    (查看该网站集中的账户) $user = Get-SPUser -web http://wfe1 -Identity 18   (将id为18的账户赋予变量$user ,不用变量下面一条语句会失败,18也可以用用户名取代) Move-SPUser -IgnoreSID -Identity $user -NewAlias 'test\sale02'   (将该账户迁移为新账户,可以在同一个域中,也可以不同域) 该操作在web

[SharePoint 2010] SharePoint 2010 部署、收回和删除解决方案----STSADM和PowerShell

STSADM stsadm -o addsolution –filename c:\bin\CustomerSiteSearch.wsp stsadm -o deploysolution –name CustomerSiteSearch.wsp -url http://[ServerName] -allowgacdeployment -force –immediate stsadm -o activatefeature –name customersitesearch_feature1 -url

[PowerShell Utils] Automatically Change DNS and then Join Domain

I would like to start a series of blog posts sharing PowerShell scripts to speed up our solution operations. Today, I am going to share a script file that can select a network adapter, changes its DNS address, then join the server to the domain you s

部署解决方案----STSADM和PowerShell

部署解决方案----STSADM和PowerShell 因为最近总是要部署wsp解决方案,所以经常要用到命令行或者PowerShell,所以有必要将命令集中放在这里,在部署的时候能够快速的参考. STSADM stsadm -o addsolution –filename c:\bin\CustomerSiteSearch.wsp stsadm -o deploysolution –name CustomerSiteSearch.wsp -url http://[ServerName] -all

SharePoint开发 - 使用Session(代码修改webconfig)

SharePoint启用Session可以使用Powershell,戳这里:可以修改webconfig. 本篇叙述的重点是通过feature去控制启用session和关闭session. 新建一个空的SharePoint项目,编写FeatureEventHandler的FeatureActivated和FeatureDeactivating的处理逻辑 public override void FeatureActivated(SPFeatureReceiverProperties propert

又是一堆免费的电子书

Largest collection of FREE Microsoft eBooks ever, including: Windows 8.1, Windows 8, Windows 7, Office 2013, Office 365, Office 2010, SharePoint 2013, Dynamics CRM, PowerShell, Exchange Server, Lync 2013, System Center, Azure, Cloud, SQL Server, and

在没有域环境的情况下配置完整安装的SharePoint2010和2013

完整安装SharePoint2010.完成后先不要运行配置向导. 配置数据库.SharePoint会安装一个POWERSHELL在这里14\CONFIG\POWERSHELL\Registration.运行该目录下的psconsole会打开一个命令行窗口.执行 New-SPConfigurationDatabase[回车] DatabaseName <config database name> DatabaseServer <servername> [注意这里必须是机器名,请右键电

[it-ebooks]电子书列表

#### it-ebooks电子书质量不错,但搜索功能不是很好 #### 格式说明  [ ]中为年份      ||  前后是标题和副标题  #### [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Objective-C to develop iPhone games http://it-ebooks.info/book/3544/ Learning Web App Developmen

(转) [it-ebooks]电子书列表

[it-ebooks]电子书列表 [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Objective-C to develop iPhone games http://it-ebooks.info/book/3544/Learning Web App Development || Build Quickly with Proven JavaScript Techniques http://