Logo

Create – Edit – Find – Delete SharePoint Alerts using PowerShell

photo

2024年01月22日

Welcome to another PowerShell walk-through. In this article I’m exploring Management of SharePoint Alerts using PowerShell!

Enable or disable alerts for Web application

## To enable alerts for Web application
 
$SPwebapp=Get-SPWebApplication "https://SharePointSite.com"
$SPwebapp.AlertsEnabled = $true
$SPwebapp.Update()
 
# To Disable alerts for a Web application
$SPwebapp.AlertsEnabled = $false
$SPwebapp.Update()


#Read more: https://www.sharepointdiary.com/2011/11/managing-alerts-using-powershell.html#ixzz8PXZ2TVL0

Create Alert in SharePoint using PowerShell

##### Create a New alert for a user #########
 
$SPsite = Get-SPSite "https://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()


#Read more: https://www.sharepointdiary.com/2011/11/managing-alerts-using-powershell.html#ixzz8PXZ8chxj

Get all alerts from a SharePoint List with PowerShell:

##### Display All alerts for a Particular List ########
 
$SPWeb = Get-SPWeb "https://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()


#Read more: https://www.sharepointdiary.com/2011/11/managing-alerts-using-powershell.html#ixzz8PXZFzEkd

Create Alerts for All users in a Group:

##### Set alerts for all users in the SharePoint Group ######
 
$SPweb = Get-SPWeb "https://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()


#Read more: https://www.sharepointdiary.com/2011/11/managing-alerts-using-powershell.html#ixzz8PXZKSeh9

Update SharePoint Alerts using PowerShell

#####  Making Changes in Existing Alerts ########
$SPsite = Get-SPSite "https://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()
}


#Read more: https://www.sharepointdiary.com/2011/11/managing-alerts-using-powershell.html#ixzz8PXZQ3OKW

Get Alerts for a Particular User

##### Get alerts for a particular user #########
$SPsite = Get-SPSite "https://SharePointSite.com"
$SPweb=$SPsite.RootWeb
$SPuser=$SPweb.EnsureUser('Domain\Salaudeen')
$SPalertCollection=$SPuser.Alerts
foreach($alert in $SPalertCollection)
{
   write-host -f Green $alert.Title
}


#Read more: https://www.sharepointdiary.com/2011/11/managing-alerts-using-powershell.html#ixzz8PXZSYmZD

Find All Alerts of a User in Entire Site collection

##### Get the Alerts of Entire Site collection #####
$SPsiteCollection = Get-SPSite "https://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
     }
 }


#Read more: https://www.sharepointdiary.com/2011/11/managing-alerts-using-powershell.html#ixzz8PXZYEknP

Delete All SharePoint alerts from a List using PowerShell

##### Delete All alerts for a specific List #####
 
$SPweb = Get-SPWeb "https://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)
}


#Read more: https://www.sharepointdiary.com/2011/11/managing-alerts-using-powershell.html#ixzz8PXZc70EE

Delete user alerts in SharePoint with PowerShell

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Configuration Parameters
$SiteURL="https://portal.crescent.com/ "
$Email = "salaudeen.rajack@crescent.com"
$Subject = "Test Email from SharePoint"
$Body = "Test Email Body"
 
#Get the Web
$Web = Get-SPWeb $SiteURL
 
#Send Email using SPUtility SendEmail method
[Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($Web ,0,0,$Email,$Subject,$Body)


#Read more: https://www.sharepointdiary.com/2016/09/how-to-test-outgoing-emails-in-sharepoint-using-powershell.html#ixzz8PXSqQTxT

Finally, some minimized code:

To delete all alerts from a site:
$SPweb.Alerts| foreach-object {$web.Alerts.Delete($_.Id)}

Filter the alerts for a single list:
#For for e.g. https://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”

橙子主题打折出售

其实我不卖,主要是这里是放广告的,所以就放了一个
毕竟主题都没做完,卖了也是坑.

购买它
所有附件
该文章没有附件.
本文为原创文章,请注意保留出处!

留言板

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

热门文章

无法握住的故土 在我们心灵最温暖的角落,总有一寸土地是属于故乡的。虽然我们看似已远离故土,可骨子里对故乡的依恋却是从未冷却过。我们无论漂泊他乡,还是在繁华都市平步青云,可故乡的悠悠情思总会潜入梦乡与你缠绵。是儿时那一缕缕茉莉的清香萦绕在梦境,也是邻家那已锈迹斑斑的铁壶里,开出艳丽的花儿在梦的边缘摇曳。故土就这样根深蒂固地在我们的灵魂深处烙下深深的印记。 作者:Pastore Antonio
1596 浏览量
EWS(Exchange Service)基本使用(获取个人会议,会议室会议内容,会议室列表,发送会议,修改会议,删除会议) 最近公司要求和exchange服务对接,所以稍微研究了一下官方文档,做出以下总结,欢迎大家补充。先...EWS(ExchangeService)基本使用(获取个人会议,会议室会议内容,会议室列表,发送会议,修改会议,删除会议) 作者:Pastore Antonio
1585 浏览量
Sql Server 部署SSIS包完成远程数据传输 本篇介绍如何使用SSIS和作业完成自动更新目标数据任务。**温馨提示:如需转载本文,请注明...SqlServer部署SSIS包完成远程数据传输 作者:Pastore Antonio
1578 浏览量
SQL Server AG集群启动不起来的临时自救大招 背景前晚一朋友遇到AG集群发生来回切换不稳定的情况,情急之下,朋友在命令行使用命令重启WSFC集群...SQLServerAG集群启动不起来的临时自救大招 作者:Pastore Antonio
1572 浏览量
windows 下安装 memcahce 官网上并未提供Memcached的Windows平台安装包,我们可以使用以下链接来下载,你需...windows下安装memcahce 作者:Pastore Antonio
1566 浏览量