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

[玩转系统] 使用 PowerShell 将 SharePoint 警报从一个用户复制到另一个用户

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

使用 PowerShell 将 SharePoint 警报从一个用户复制到另一个用户


要求: 将 SharePoint 警报从一个用户复制到另一个用户。

PowerShell 将 SharePoint 警报从一个用户复制到另一个用户:

我们希望为新用户创建警报,就像要离开组织的现有用户一样。


Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

Function Copy-SPAlerts($SiteURL, $SourceUserAccount, $TargetUserAccount)
{
   #Get the Site
   $Site = Get-SPSite $SiteURL

   #Iterate through each web
   foreach($web in $site.AllWebs)
   {
      #Resolve users
      $SourceUser=$web.EnsureUser($SourceUserAccount)
      $TargetUser = $web.EnsureUser($TargetUserAccount)
  
      #Get all alerts from the source user
      $SourceAlertCollection=$SourceUser.Alerts
  
      #loop through each alert of the source user and copy it to target suer
      foreach($SourceAlert in $SourceAlertCollection)
      {
         Write-host "Copying Alert from: $($Web.Url)/$($SourceAlert.ListUrl)"
  
         #Copy alerts from source user to destination
         $NewAlert = $TargetUser.Alerts.Add()
         $NewAlert.Title = $SourceAlert.Title
         $NewAlert.AlertType = $SourceAlert.AlertType
         $NewAlert.User = $TargetUser
         $NewAlert.List = $SourceAlert.List
         $NewAlert.DeliveryChannels = $SourceAlert.DeliveryChannels
         $NewAlert.EventType =  $SourceAlert.EventType
         $NewAlert.AlertFrequency = $SourceAlert.AlertFrequency
         $NewAlert.Update()
      }
   }
}

#Configuration variables
$SiteURL="https://portal.crescent.com"
$SourceUserAccount="Crescent\Jitin"
$TargetUserAccount ="Crescent\Nassim"

#Call the function to copy alerts
Copy-SPAlerts $SiteURL $SourceUserAccount $TargetUserAccount 

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

取消回复欢迎 发表评论:

关灯