Guest User

Untitled

a guest
Jun 2nd, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. # URL to SharePoint site where you want to add an alert
  2. $siteUrl = ""
  3. # SharePoint user name you want to create the alert for
  4. $username = ""
  5. # SharePoint user password in plain text
  6. $password = ""
  7. $listname = "Documents"
  8.  
  9. # Load SharePoint client dlls (get them from nuget.org and place them along with this PS1 file)
  10. # For instance Microsoft.SharePointOnline.CSOM or Microsoft.SharePoint2013.CSOM
  11. [System.Reflection.Assembly]::LoadFile("$PSScriptRootMicrosoft.SharePoint.Client.dll")
  12. [System.Reflection.Assembly]::LoadFile("$PSScriptRootMicrosoft.SharePoint.Client.Runtime.dll")
  13.  
  14. $context = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
  15. $securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
  16. $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
  17.  
  18. # Get list from SharePoint
  19. $list = $context.Web.Lists.GetByTitle($listname)
  20.  
  21. # Load needed information from SharePoint Online
  22. $currentUser = $context.Web.CurrentUser
  23. $context.Load($currentUser)
  24. $context.ExecuteQuery()
  25.  
  26. # Create new alert using CSOM for the user
  27. $alert = New-Object Microsoft.SharePoint.Client.AlertCreationInformation
  28. $alert.List = $context.Web.Lists.GetByTitle("Documents")
  29. $alert.AlertFrequency = [Microsoft.SharePoint.Client.AlertFrequency]::Immediate
  30. $alert.AlertType = [Microsoft.SharePoint.Client.AlertType]::List
  31. $alert.AlwaysNotify = $false
  32. $alert.DeliveryChannels = [Microsoft.SharePoint.Client.AlertDeliveryChannel]::Email
  33. $alert.Status = [Microsoft.SharePoint.Client.AlertStatus]::On
  34. $alert.Title = "New alert created at : " + [System.DateTime]::Now
  35. $alert.User = $currentUser
  36. $alert.EventType = [Microsoft.SharePoint.Client.AlertEventType]::All
  37. $alert.Filter = "0"
  38. # 0 = Anything Changes
  39. # 1 = Someone else changes a document
  40. # 2 = Someone else changes a document created by me
  41. # 3 = Someone else changes a document modified by me
  42.  
  43. # Add the alert for the user
  44. $newAlertGuid = $currentUser.Alerts.Add($alert)
  45. $currentUser.Update()
  46.  
  47. # Execute creation request to the SPO
  48. $context.ExecuteQuery();
Add Comment
Please, Sign In to add comment