【问题标题】:Delete Outlook Appointment via Powershell通过 Powershell 删除 Outlook 约会
【发布时间】:2021-04-27 05:06:38
【问题描述】:

我需要创建一个 Powershell 脚本来删除 User Site 上的 Outlook 约会,而不是使用 Exchange 命令行管理程序。我已经制作了一个脚本,它在User Site 上创建了一个Appointment,但我没有找到太多关于在User Site 上删除Appointments 的信息。

这是我已经尝试过的:

  1. User Site 上创建Appointment(也许在这个函数中可以反转一些东西?)

             $outlook = new-object -comObject Outlook.Application
             $olNamespace = $outlook.GetNamespace("MAPI")
             $calendar = $olNamespace.Folders.Item("$Kalender") 
             $olAppointmentItem = 1
    
             $termin = $calendar.Items.Add("IPM.Appointment")
    
    
             $termin.start = ($Date)
             $termin.duration = ( 60 * 24  )
             $termin.subject = "Closed"
             $termin.ReminderSet = $False
             $termin.Categories = "Closed"
             $result = $termin.save()
    
  2. 我在这里尝试使用 Exchange 命令行管理程序(但这不是我正在寻找的解决方案..)

     Search-Mailbox -Identity "User" -SearchQuery {Subject:"Test" AND Send:"04/20/2020"}
    
     New-ComplianceSearch -Name "RemoveCalendar1" -ExchangeLocation All -ContentMatchQuery "'calendar 
     subject line'"
    

感谢您的帮助!

【问题讨论】:

    标签: powershell


    【解决方案1】:

    类似。您只需要确定要删除的项目。如下所示,使用Where-Object

    $outlook = New-Object -ComObject Outlook.Application
    $olNamespace = $outlook.GetNamespace('MAPI')
    $calendar = $olNamespace.Folders.Item("$Kalender") 
    
    # Find appointments with Title 'Test' scheduled for today
    $itemsToBeDeleted = $calendar.Items | Where-Object { $_.ConversationTopic -eq 'Test' -and $_.start.date -eq (Get-Date).date }
    
    # Delete items
    $itemsToBeDeleted.Delete()
    

    这可能很危险,因为可能会无意中删除项目。过滤要非常具体。在执行删除命令之前,您可能需要检查$itemsToBeDeleted.Count

    if ($itemsToBeDeleted.Count -gt 1) {
        $itemsToBeDeleted | Select-Object ConversationTopic, Start | Out-Host
        Write-Warning "Multiple items selected for deletion.  Are you sure you want to continue?" -WarningAction Inquire
    }
    
    # Delete items
    $itemsToBeDeleted.Delete()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 2021-03-12
      • 1970-01-01
      相关资源
      最近更新 更多