Exchange Online-EWS API-删除日历项目 [英] Exchange Online - EWS API - removing calendar items

查看:68
本文介绍了Exchange Online-EWS API-删除日历项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Outlook,我要删除旧日历"项.

Outlook , I want to remove the 'Old Calendar' items.

我的工作流程是:

  • 首先清除每个日历中的项目,然后确认其为空并删除.

但是,我已经检查了下面的行.但是 $ oFindFolderResults 为空.

But , I have checked below line. But $oFindFolderResults is null.

$oFindFolderResults = $service.FindFolders([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,$oSearchFilter,$oFolderView)

推荐答案

您的代码将始终绑定到您使用的安全凭据的邮箱,因为如果您要使用的则没有包括任何模拟代码(您的代码注释表明了这一点),或者如果您要使用委托访问,则需要使用FolderId重载.

Your code will always bind to the Mailbox of the Security credentials your using because you haven't included any impersonation code if that's what you want to use (your code comments indicate this) or if you want to use delegate access you need to use the FolderId overload.

要进行模拟,您需要添加

For impersonation you need to add

$service.ImpersonatedUserId = new-object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName) 

还添加锚点邮箱标题,例如

Also add the Anchor mailbox header eg

$service.HttpHeaders.Add("X-AnchorMailbox", $MailboxName);

对于委派甚至是假冒,我都会使用

For delegation or even with impersonation i would use

    $folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root, $MailboxName)   
    $oFindFolderResults = $service.FindFolders($folderid,$oSearchFilter,$oFolderView)

这将确保您始终在$ MailboxName变量中搜索邮箱

That will ensure your always searching the Mailbox in the $MailboxName variable

要删除项目,请尝试类似的操作(其中$ Calendar是目标文件夹)

for deleting items try something like (where $Calendar is you target folder)

$ivItemView = New-Object Microsoft.Exchange.WebServices.Data.ItemView(1000)  
$fiResult = ""  
do{  
    $fiResult = $Calendar.FindItems($ivItemView)  
    $type = ("System.Collections.Generic.List" + '`' + "1") -as "Type"
    $type = $type.MakeGenericType("Microsoft.Exchange.WebServices.Data.ItemId" -as "Type")
    $Itemids = [Activator]::CreateInstance($type)
    "Delete " + $fiResult.Items.Count + " Items"  
    foreach($Item in $fiResult.Items){  
        $Itemids.Add($Item.Id)  
    }  
    #Delete the Items  
    $Result = $service.DeleteItems($Itemids,[Microsoft.Exchange.WebServices.Data.DeleteMode]::SoftDelete,[Microsoft.Exchange.WebServices.Data.SendCancellationsMode]::SendToNone,[Microsoft.Exchange.WebServices.Data.AffectedTaskOccurrence]::AllOccurrences)  
    [INT]$Rcount = 0  
    foreach ($res in $Result){  
        if ($res.Result -eq [Microsoft.Exchange.WebServices.Data.ServiceResult]::Success){  
            $Rcount++  
        }  
    }  
    $Rcount.ToString() + " Items deleted successfully"  
    $ivItemView.offset += $fiResult.Items.Count  
}while($fiResult.MoreAvailable -eq $true)  

这篇关于Exchange Online-EWS API-删除日历项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆