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

[玩转系统] SharePoint Online:使用 PowerShell 更改警报计划

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

SharePoint Online:使用 PowerShell 更改警报计划


要求:将 SharePoint Online 网站集中特定用户的所有警报的警报计划从“立即”更改为“每日”。

业务案例:SharePoint 用户订阅了 SharePoint Online 网站集中的各种列表和库中的警报。警报以“立即”的频率创建,由于内容经常添加到这些 SharePoint 列表中,因此充斥着他的收件箱。因此,用户希望将他创建的所有警报的警报频率更改为每日摘要。如何在 SharePoint 中将警报频率从立即更改为每天?

SharePoint 用户可以通过以下方式更新任何现有警报:

  1. 转至创建警报的列表或库 >> 从列表设置工具栏中单击“管理我的警报”。
  2. 从显示的警报列表中选择警报,以在编辑模式下打开它。
  3. 现在您可以调整警报的任何属性,例如频率、时间表、更改类型等。

    [玩转系统] SharePoint Online:使用 PowerShell 更改警报计划

更新大型网站集中的每个警报并不是一件容易的事,不是吗?因此,让我们使用 PowerShell 更新 SharePoint Online 网站集中用户的所有警报。

PowerShell 更改 SharePoint Online 中的警报计划:

让我们使用 PowerShell 更改 SharePoint Online 网站集中特定用户的所有警报的计划。


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#Custom Function to Set Alert Schedule 
Function Set-SPOAlertSchedule()
{ 
    param
    (
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $UserID,
        [Parameter(Mandatory=$true)] [string] $Schedule
    )
    Try {
        Write-host -f Yellow "Searching Site '$SiteURL' for Alerts of the User '$UserID'"

        #Setup Credentials to connect
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
    
        #Get the web and its sub-sites
        $Web = $Ctx.Web
        $Ctx.Load($Web)
        $Ctx.Load($Web.Webs)
        $Ctx.ExecuteQuery()

        #Get All Alerts of the User
        $User = $Web.EnsureUser($UserID)
        $UserAlerts = $User.Alerts
        $Ctx.Load($User)
        $Ctx.Load($UserAlerts)
        $Ctx.ExecuteQuery()

        #Loop through each alert
        #Write-host "Total Alerts of the User:"$UserAlerts.Count
        ForEach($Alert in $UserAlerts)
        {
            $Ctx.Load($Alert.List)
            #Update the Alert Schedule
            $Alert.AlertFrequency = [Microsoft.SharePoint.Client.AlertFrequency]::$Schedule 
            $Alert.UpdateAlert()
            $Ctx.ExecuteQuery()
            Write-host -f Green "Alert '$($Alert.Title)' Updated on list '$($Alert.List.Title)'!"
        }

        #Iterate through each subsite of the current web and call the function recursively
        foreach ($Subweb in $Ctx.web.Webs)
        {
            #Call the function recursively to process all subsites underneaththe current web
            Set-SPOAlertSchedule -SiteURL $Subweb.url -UserID $UserID -Schedule "Daily"
        }
    }
    Catch {
        write-host -f Red "Error Updating Alert!" $_.Exception.Message
    }
}

#Call the function
Set-SPOAlertSchedule -SiteURL "https://Crescent.sharepoint.com/" -UserID "[email protected]" -Schedule "Daily" 

默认情况下,SharePoint Online 中的警报设置为在进行更改后立即发送通知,但您也可以设置警报以按照本文所述的计划发送通知。更改 SharePoint Online 中的警报计划是一个简单的过程,可以帮助您更有效地管理警报。通过执行本文中概述的步骤,您可以轻松修改特定列表或库的警报计划,并确保您在适当的时间收到通知。

您可以使用 PowerShell 更新本地 SharePoint 中的警报:如何使用 PowerShell 更新 SharePoint 警报

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

取消回复欢迎 发表评论:

关灯