ค้นหาเว็บไซต์

SharePoint Online: สร้างการแจ้งเตือนโดยใช้ PowerShell


ความต้องการ: สร้างการแจ้งเตือน SharePoint โดยใช้ PowerShell

จะสร้างการแจ้งเตือนใน SharePoint Online ได้อย่างไร

การแจ้งเตือนใน SharePoint Online ช่วยในการติดตามการเปลี่ยนแปลง เช่น การเพิ่ม/การเปลี่ยนแปลง/การลบเนื้อหา เช่น รายการและไลบรารี หน้า ฯลฯ คุณสามารถระบุเงื่อนไขที่คุณต้องการรับการแจ้งเตือนและความถี่ที่คุณต้องการรับ พวกเขา. เมื่อต้องการสร้างการแจ้งเตือนสำหรับไลบรารีเอกสาร SharePoint Online ให้ทำตามขั้นตอนเหล่านี้:

  1. ไปที่ไซต์ SharePoint Online ของคุณ นำทางไปยังไลบรารีเอกสารที่คุณต้องการสร้างการแจ้งเตือน
  2. จากแถบเครื่องมือ คลิกที่จุดไข่ปลาและเลือก "แจ้งเตือนฉัน"

  3. ในหน้าการสร้างการแจ้งเตือนใหม่ ให้พิมพ์ชื่อการแจ้งเตือน ป้อนผู้ใช้ที่จะได้รับการแจ้งเตือน และเลือกอีเมลหรือ SMS สำหรับ "วิธีการจัดส่ง" เลือกเงื่อนไขสำหรับการแจ้งเตือนนี้ (เช่น "มีอะไรเปลี่ยนแปลง") และเวลาที่จะส่งการแจ้งเตือน

  4. เลื่อนไปที่ด้านล่างของหน้าแล้วคลิก "ตกลง" เพื่อสร้างการแจ้งเตือนสำหรับไลบรารีเอกสาร

ตอนนี้ เรามาสร้างการแจ้งเตือน SharePoint Online โดยใช้ PowerShell กันดีกว่า!

SharePoint Online: CSOM PowerShell เพื่อสร้างการแจ้งเตือน

เมื่อมีการเพิ่มรายการใหม่ เราต้องการเพิ่มการแจ้งเตือนทางโปรแกรมโดยใช้ PowerShell ลงในรายการ SharePoint Online


#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"
   
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com"
$ListName="Documents"
$UserID="Salaudeen@crescent.com"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
 
Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred
   
    #Get the List and User Objects
    $List = $Ctx.Web.Lists.GetByTitle($ListName)
    $User = $Ctx.Web.EnsureUser($UserID)
    $Ctx.Load($List)
    $Ctx.Load($User)
    $Ctx.ExecuteQuery()

    #Create new alert Object and Set its Properties
    $Alert = New-Object Microsoft.SharePoint.Client.AlertCreationInformation
    $Alert.List = $List
    $Alert.User = $User
    $Alert.Title = "New Documents in Project Docs - Alert"
    $Alert.AlertFrequency = [Microsoft.SharePoint.Client.AlertFrequency]::Immediate
    $Alert.AlertType = [Microsoft.SharePoint.Client.AlertType]::List
    $Alert.DeliveryChannels = [Microsoft.SharePoint.Client.AlertDeliveryChannel]::Email
    $Alert.Status = [Microsoft.SharePoint.Client.AlertStatus]::On
    $Alert.EventType = [Microsoft.SharePoint.Client.AlertEventType]::AddObject #Or All
    $Alert.Filter = "0" #Anything Changes - Other values: 1, 2, 3

    # Add the alert for the user
    $AlertGuid = $User.Alerts.Add($Alert)
    $User.Update()
    $Ctx.ExecuteQuery()

    Write-host -f Green "New Alert Has been Created!"
}
Catch {
    write-host -f Red "Error Creating Alert!" $_.Exception.Message
}

PnP PowerShell เพื่อสร้างการแจ้งเตือนใหม่ใน SharePoint Online

หากคุณต้องการสร้างการแจ้งเตือนใหม่ใน SharePoint Online โดยไม่ใช้ UI PowerShell คือคำตอบ! ฉันจะแสดงวิธีใช้ PnP PowerShell cmdlet Add-PnPAlert เพื่อสร้างการแจ้งเตือนใหม่ใน SharePoint Online


Add-PnPAlert -Url <List or Library URL> -User <User or Group Email> -DeliveryMethod <Delivery method> -Frequency <Frequency> -ChangeType <Change Type>

นี่คือรายการพารามิเตอร์ที่ใช้:

  • : URL ของรายการหรือไลบรารีที่คุณต้องการสร้างการแจ้งเตือน
  • <อีเมลผู้ใช้หรือกลุ่ม>: ที่อยู่อีเมลของผู้ใช้หรือกลุ่มที่คุณต้องการสร้างการแจ้งเตือนให้
  • <วิธีการจัดส่ง>: ประเภทการแจ้งเตือนที่คุณต้องการสร้าง เช่น "อีเมล" หรือ "SMS"
  • : ความถี่ที่คุณต้องการรับการแจ้งเตือน เช่น "ทันที" หรือ "รายสัปดาห์"
  • <ประเภทการเปลี่ยนแปลง>: ประเภทการเปลี่ยนแปลงที่คุณต้องการรับการแจ้งเตือน เช่น “ทั้งหมด” หรือ “ใหม่”

ตัวอย่างเช่น หากต้องการสร้างการแจ้งเตือนสำหรับ “เอกสาร” บน URL ของไซต์ “https://crescent.sharepoint.com/sites/Branding” และส่งการแจ้งเตือนทางอีเมลรายวันไปยังผู้ใช้ด้วยที่อยู่อีเมล “Steve@Crescent.com” สำหรับ การเปลี่ยนแปลงทั้งหมด คุณสามารถใช้คำสั่งต่อไปนี้:


#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Branding"
$UserId= "i:0#.f|membership|Steve@crescent.com"

Try {
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Interactive
 
    #Create an Alert
    Add-PnPAlert -Title "Documents Alert" -List "Documents" -User $UserId -Frequency Daily -ChangeType All
      
    Write-host "New Alert has been Created for the given user!" -f Green    
}
Catch {
    Write-host -f Red "Error:" $_.Exception.Message
}

บทความที่เกี่ยวข้อง