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()
}
How to Operate SharePoint User Alerts with PowerShell的更多相关文章
- SharePoint自动化系列——通过PowerShell创建SharePoint Lists
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PS ...
- SharePoint自动化系列——通过PowerShell创建SharePoint List Items
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PS ...
- SharePoint自动化系列——通过PowerShell创建SharePoint Web
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PS ...
- SharePoint自动化系列——通过PowerShell创建SharePoint Site Collection
通过PowerShell创建SharePoint Site Collection,代码如下: Add-PSSnapin microsoft.sharepoint.powershell function ...
- SharePoint自动化系列——通过PowerShell在SharePoint中批量做数据
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ PowerShell是基于.NET的一门脚本语言,对于SharePoint一些日常操作支持的很好. ...
- SharePoint 解决方案和功能-PowerShell
1. 添加解决方案到SharePoint场 Add-SPSolution "c:\newsolution.wsp" 2. 获取场中的解决方案 Get-SPSolution 3. 获 ...
- 【SharePoint学习笔记】第2章 SharePoint Windows PowerShell 指南
快速了解Windows PowerShell 从SharePoint 2010开始支持PowerShell,仍支持stsadm.exe工具: 可以调用.NET对象.COM对象.exe文 ...
- SharePoint自动化部署,利用PowerShell 导出/导入AD中的用户
这几个月一直在帮客户改需求,部署.我已经心力憔悴,经过一段时间的摸索,我对用PowerShell实现自动化部署也有了一些心得,比如说利用PowerShell导出导入AD中的User.在基于ShareP ...
- [SharePoint 2010] SharePoint 2010 部署、收回和删除解决方案----STSADM和PowerShell
STSADM stsadm -o addsolution –filename c:\bin\CustomerSiteSearch.wsp stsadm -o deploysolution –name ...
随机推荐
- 【Win10应用开发】通过拖放来打开文件
除了可以使用XXXFilePicker来浏览文件外,其实在UWP APP中,也可以向传统Windows窗口一样,通过拖放的方式来打开文件. 处理过程和WPF的原理差不多,毕竟都是一脉相承,于是,在学习 ...
- 【Win 10 应用开发】打印UI元素
Windows App支持将UI界面进行打印的功能,这与浏览器中的打印网页的用途相近,其好处就是“所见即所得”,直接把界面上呈现的内容打印下来,比重新创建打印图像方便得多. 要在通用App中实现打印, ...
- 【转】C#调用Windows图片和传真查看器打开图片
//建立新的系统进程 System.Diagnostics.Process process = new System.Diagnostics.Process(); //设置文件名,此处为图片的真实路径 ...
- ELF文件
ELF文件格式是一个开发标准,各种UNIX系统的可执行文件都采用ELF格式,它有三种不同的类型: 可重定位的目标文件 可执行文件 共享库 现在分析一下上一篇文章中经过汇编之后生成的目标文件max.o和 ...
- c/c++多线程模拟系统资源分配(并通过银行家算法避免死锁产生)
银行家算法数据结构 (1)可利用资源向量Available 是个含有m个元素的数组,其中的每一个元素代表一类可利用的资源数目.如果Available[j]=K,则表示系统中现有Rj类资源K个. (2) ...
- Android重写菜单增加系统自带返回键
条件:当前项目导入了ActionBarSherlock这个jar包,这个jar包的作用为了程序的兼容性,考虑低版本的问题. 学习ActionBarSherlock参考博客链接:http://blog. ...
- 触屏touch事件记录
一.chrome中的Remote Debugging 一开始并没有用这个调试,不过后面需要多点触碰,可chrome模拟器中我没看到这个功能.突然看到了Remote Debugging,网站需要FQ才能 ...
- 安装最新版本的PHPUnit后,不能使用
我使用的是widows系统.本来3.7.8版本的Phpunit用的是非常顺畅的,最近重新安装phpunit,安装了最小版本,然后在使用的时候就会报很多各种错误.无奈之下只能降版本到3.7.8 首先要卸 ...
- ZOJ Problem Set - 1216 Deck
#include <stdio.h> int main() { ]; double t=2.0; table[]=0.5; ;i<;i++) { t+=; table[i]=tabl ...
- 表空间基于时间点的恢复(TSPITR)
环境:RHEL 6.4 + Oracle 11.2.0.4 准备模拟环境 1. 验证表空间的依赖性 2. 确定执行TSPITR后会丢失的对象 3. 自动执行TSPITR Reference 准备模拟环 ...