当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 禁用 SharePoint 2013 列表上的警报

作者:精品下载站 日期:2024-12-14 14:02:44 浏览:14 分类:玩电脑

使用 PowerShell 禁用 SharePoint 2013 列表上的警报


要求:暂时禁用 SharePoint 列表上的警报电子邮件。

[玩转系统] 使用 PowerShell 禁用 SharePoint 2013 列表上的警报

如何禁用 SharePoint 列表上的警报

SharePoint 警报对象具有可以打开或关闭的“状态”属性。由于没有 UI 可以直接从浏览器禁用或启用 SharePoint 中的警报,因此我们可以使用 PowerShell 以编程方式执行此操作。以下是我的 PowerShell 脚本,用于禁用 SharePoint 2010/2013 列表或库上的警报。

重要:此脚本仅禁用特定列表或库中的现有警报!它不会(当然不能!)禁用您在特定列表上创建的任何新警报!您可能需要通过将“AlertsEnabled”标志更改为“false”来暂时关闭 Web 应用程序级别的警报,如如何在 SharePoint 中禁用警报中所示

用于禁用 SharePoint 列表上的警报的 PowerShell 脚本


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Function to Disable All Active Alerts on a Given List
Function Disable-ListAlerts($WebURL, $ListName)
{
    #Get the Web and List objects
    $Web = Get-SPWeb $WebURL
    $List = $web.Lists.TryGetList($ListName)

    #Get All Alerts created in the list - Which are Active
    $ListAlerts = $Web.Alerts | Where-Object {($_.List.Title -eq $List.Title) -and ($_.Status -eq "ON")}

    Write-host "Total Number of Active Alerts Found in the list: $($ListAlerts.Count)" 
    
    #Iterate through each alert and turn it OFF
    foreach($Alert in $ListAlerts)
        {
            $Alert.Status="OFF"
            $Alert.Update()
            write-host "Disabled the Alert' $($Alert.Title)' Created for User '$($Alert.User.Name)'"
        }
         
    #Dispose web object
    $Web.Dispose()
}

#Function to Enable all Disable Alerts on a Given List
Function Enable-ListAlerts($WebURL, $ListName)
{
    #Get the Web and List objects
    $Web = Get-SPWeb $WebURL
    $List = $web.Lists.TryGetList($ListName)

    #Get All Alerts created in the list - Which are in Disabled State
    $ListAlerts = $Web.Alerts | Where-Object { ($_.List.Title -eq $List.Title) -and ($_.Status -eq "OFF")}

    Write-host "Total Number of Disabled Alerts Found in the list: $($ListAlerts.Count)" 
    
    #Iterate through each alert and turn it OFF
    foreach($Alert in $ListAlerts)
        {
            $Alert.Status="ON"
            $Alert.Update()
            write-host "Enabled the Alert' $($Alert.Title)' Created for User '$($Alert.User.Name)'"
        }
         
    #Dispose web object
    $Web.Dispose()
}

#Variables
$WebURL = "https://operations.crescent.com/"
$ListName="Proposal Documents"

#Call the function Appropriately to Disable or Enable Alerts 
Disable-ListAlerts $WebURL $ListName

#To Enable it back
#Enable-ListAlerts $WebURL $ListName
请注意,您必须等待五分钟才能再次启用警报(因为立即警报计时器作业会查找过去五分钟内修改的项目)。否则,您将收到来自禁用警报的电子邮件!因此:禁用警报 - 对数据进行更改 - 等待五分钟 - 再次启用警报。

相关帖子:

  • 使用 C# 禁用 SharePoint 2010 列表或库中的警报
  • 在 SharePoint 2007/2010/2013 中禁用提醒我 - 如何禁用 SharePoint 中的所有提醒?
  • 使用 PowerShell 创建 - 编辑 - 查找 - 删除 SharePoint 警报

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯