kwizcom banner advertisement

SharePoint Online: Get All Alerts from a Site Collection using PowerShell

Requirement: View all alerts in SharePoint Online site collection.

How to Get all alerts of a user in SharePoint Online?
Alerts are scoped at web level in SharePoint. So, to get alerts of a user in a specific site, follow these steps:
  • Navigate to the site >> Go to Site Settings page
  • Click on "User alerts" link under "Site Administration"
  • Select the user from the drop down and click on "Update" button to view all alerts.
    sharepoint online powershell get alerts
  • This gets you all alerts of the selected user on the current site .
Now the question is: How to view all alerts of a SharePoint Online user for a entire site collection? PowerShell!

PowerShell to Fetch All Alerts from SharePoint Online:
Here is the SharePoint Online PowerShell to get alerts from a site collection.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\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
This PowerShell script gets alerts created in site collection and generates a CSV file with all alerts in the provided site collection.
SharePoint Online: Get All Alerts from a Site Collection using PowerShell SharePoint Online: Get All Alerts from a Site Collection using PowerShell Reviewed by Salaudeen Rajack on November 17, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.