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

[玩转系统] SharePoint Online:使用 PowerShell 从网站集中获取所有警报

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

SharePoint Online:使用 PowerShell 从网站集中获取所有警报


要求:查看 SharePoint Online 网站集中的所有警报。

如何在 SharePoint Online 中获取用户的所有警报?

警报的范围在 SharePoint 中的 Web 级别。因此,要获取特定站点上用户的警报,请按照下列步骤操作:

  1. 导航至站点 >> 转至站点设置页面。
  2. 单击“站点管理”下的“用户警报”链接。
  3. 从下拉列表中选择用户,然后单击“更新”按钮以查看所有警报。

    [玩转系统] SharePoint Online:使用 PowerShell 从网站集中获取所有警报

  4. 这将为您提供当前站点上所选用户的所有警报。

现在的问题是:如何查看整个网站集的 SharePoint Online 用户的所有警报?电源外壳!

PowerShell 从 SharePoint Online 获取所有警报

以下是用于从网站集获取警报的 SharePoint Online PowerShell。


#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"
   
Function Get-SPOWebAlerts($SiteURL)
{
    Try {
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Cred
        
        Write-host -f Yellow "Getting Alerts in the site" $SiteURL
        #Get All Alerts from the Web
        $Web = $Ctx.Web
        $WebAlerts = $Web.Alerts
        $Ctx.Load($Web)
        $Ctx.Load($web.Webs)
        $Ctx.Load($WebAlerts)
        $Ctx.ExecuteQuery()

        If($WebAlerts.count -gt 0) { Write-host -f Green "Found $($WebAlerts.Count) Alerts!"}

        $AlertCollection = @()
        #Loop through each alert of the web and get alert details
        ForEach($Alert in $webAlerts)
        {
            #Get Alert list and User
            $Ctx.Load($Alert.User)
            $Ctx.Load($Alert.List)
            $Ctx.ExecuteQuery()

            $AlertData = New-Object PSObject
            $AlertData | Add-Member NoteProperty SiteName($Web.Title)
            $AlertData | Add-Member NoteProperty SiteURL($Web.URL)
            $AlertData | Add-Member NoteProperty AlertTitle($Alert.Title)
            $AlertData | Add-Member NoteProperty AlertUser($Alert.User.Title)
            $AlertData | Add-Member NoteProperty AlertList($Alert.List.Title)
            $AlertData | Add-Member NoteProperty AlertFrequency($Alert.AlertFrequency)
            $AlertData | Add-Member NoteProperty AlertType($Alert.AlertType)
            $AlertData | Add-Member NoteProperty AlertEvent($Alert.EventType)
                      
            #Add the result to an Array
            $AlertCollection += $AlertData
        }
        #Export Alert Details to CSV file
        $AlertCollection | Export-CSV $ReportOutput -NoTypeInformation -Append

        #Iterate through each subsite of the current web and call the function recursively
        foreach ($Subweb in $web.Webs)
        {
            #Call the function recursively to process all subsites underneath the current web
            Get-SPOWebAlerts($Subweb.url)
        }
    }
    Catch {
        write-host -f Red "Error Getting Alerts!" $_.Exception.Message
    }
}

#Config Parameters
$SiteURL= "https://crescent.sharepoint.com/"
$ReportOutput="C:\Temp\AlertsRpt.csv"

#Delete the Output Report, if exists
if (Test-Path $ReportOutput) { Remove-Item $ReportOutput }

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

#Call the function
Get-SPOWebAlerts $SiteURL

此 PowerShell 脚本获取在网站集中创建的警报,并生成一个 CSV 文件,其中包含所提供网站集中的所有警报。

PnP PowerShell 用于获取网站中用户的所有警报

要获取 SharePoint Online 网站中用户的所有警报,请使用以下 PowerShell:


#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$UserID = "i:0#.f|membership|salaudeen@crescent.com"

#Connect to SharePoint Online site
Connect-PnPOnline $SiteURL -interactive

#Get the User
$User = Get-PnPUser -Identity $UserID

#Get All Alerts of the User in the web
$Alerts = Get-PnPAlert -User $User

$AlertData=@()
ForEach($Alert in $Alerts)
{
    #Get the List and List URL of the Alert
    $AlertList =  Get-PnPProperty -ClientObject $Alert -Property List
    $ListURL =  Get-PnPProperty -ClientObject $AlertList -Property DefaultViewURL

    #Fetch Alert Data
    $AlertData += New-Object PSObject -Property @{
        Title = $Alert.Title
        List = $AlertList.Title
        URL = $ListURL
        Frequency = $Alert.AlertFrequency
        AlertType = $Alert.AlertType
        EventType = $Alert.EventType
    }
}
$AlertData 

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

取消回复欢迎 发表评论:

关灯