Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # URL to SharePoint site where you want to add an alert
- $siteUrl = ""
- # SharePoint user name you want to create the alert for
- $username = ""
- # SharePoint user password in plain text
- $password = ""
- $listname = "Documents"
- # Load SharePoint client dlls (get them from nuget.org and place them along with this PS1 file)
- # For instance Microsoft.SharePointOnline.CSOM or Microsoft.SharePoint2013.CSOM
- [System.Reflection.Assembly]::LoadFile("$PSScriptRootMicrosoft.SharePoint.Client.dll")
- [System.Reflection.Assembly]::LoadFile("$PSScriptRootMicrosoft.SharePoint.Client.Runtime.dll")
- $context = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
- $securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
- $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
- # Get list from SharePoint
- $list = $context.Web.Lists.GetByTitle($listname)
- # Load needed information from SharePoint Online
- $currentUser = $context.Web.CurrentUser
- $context.Load($currentUser)
- $context.ExecuteQuery()
- # Create new alert using CSOM for the user
- $alert = New-Object Microsoft.SharePoint.Client.AlertCreationInformation
- $alert.List = $context.Web.Lists.GetByTitle("Documents")
- $alert.AlertFrequency = [Microsoft.SharePoint.Client.AlertFrequency]::Immediate
- $alert.AlertType = [Microsoft.SharePoint.Client.AlertType]::List
- $alert.AlwaysNotify = $false
- $alert.DeliveryChannels = [Microsoft.SharePoint.Client.AlertDeliveryChannel]::Email
- $alert.Status = [Microsoft.SharePoint.Client.AlertStatus]::On
- $alert.Title = "New alert created at : " + [System.DateTime]::Now
- $alert.User = $currentUser
- $alert.EventType = [Microsoft.SharePoint.Client.AlertEventType]::All
- $alert.Filter = "0"
- # 0 = Anything Changes
- # 1 = Someone else changes a document
- # 2 = Someone else changes a document created by me
- # 3 = Someone else changes a document modified by me
- # Add the alert for the user
- $newAlertGuid = $currentUser.Alerts.Add($alert)
- $currentUser.Update()
- # Execute creation request to the SPO
- $context.ExecuteQuery();
Add Comment
Please, Sign In to add comment