Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

[E2010] [EWSMA] [PowerShell] [Windows]: Hidden Delegate Forward Rule, "Object cannot be deleted."

$
0
0

Hello,

Exchange Version: Version 14.2 (Build 247.5)

I am using EWS Managed API 2.1 within Powershell.

Cached Exchange mode is on by default.

I have been attempting to delete the hidden delegate forwarding rule using EWS and been unsuccessful so far. I am using code that has at least worked for some people out there but I am unsure why it is not working for me. Every other command works for me no problem, such as getting information or adding/removing delegates (even deleting the ghost delegate information in the FreeBusy Information Message).

I have verified that I have FullAccess to the mailbox via Get-MailboxPermission and I have also attempted to give myself Owner on the Inbox in case that permission was also needed. I have tried using impersonation and also using access without impersonation and neither work. I am able to right-click and delete this object in MFCMapi though.

The Powershell error I get is the following:

Exception calling "Delete" with "1" argument(s): "Object cannot be deleted."

The EWS trace error I get is:

<Trace Tag="EwsResponse" Tid="13" Time="2014-06-11 19:03:36Z" Version="15.00.0847.030"><?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><h:ServerVersionInfo MajorVersion="14" MinorVersion="2" MajorBuildNumber="318" MinorBuildNumber="4" Version="Excha
nge2010_SP2" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exc
hange/services/2006/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSc
hema" /></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><m:DeleteItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schem
as.microsoft.com/exchange/services/2006/types"><m:ResponseMessages><m:DeleteItemResponseMessage ResponseClass="Error"><m:MessageText>Object cannot be deleted.</m:MessageText><m:ResponseCode>ErrorCannotDeleteObject</m:ResponseCode><m:DescriptiveLinkKey>0</m:DescriptiveLinkKey></m:DeleteItemResponseMessage></m:ResponseMessages></m:DeleteItemResponse></s:Body></s:Envelope></Trace>

The code that I am using to delete the message is the following:

$exchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP2
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($exchangeVersion)
$service.UseDefaultCredentials = $true 

$mailbox = Get-Mailbox $mailbox
$mailboxPrimarySMTP = $mailbox.PrimarySMTPAddress.ToString()

$impersonatedUserId = New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId -ArgumentList ([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress),$mailboxPrimarySMTP
$service.ImpersonatedUserId = $impersonatedUserId
$service.AutoDiscoverURL($mailboxPrimarySMTP)

# Setup Basic EWS Properties for Message Search - Used to locate Hidden Forwarding Rule
$searchFilterForwardRule         = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+ContainsSubstring([Microsoft.Exchange.WebServices.Data.ItemSchema]::ItemClass, "IPM.Rule", [Microsoft.Exchange.WebServices.Data.ContainmentMode]::Prefixed, [Microsoft.Exchange.WebServices.Data.ComparisonMode]::Exact)
$itemViewForwardRule             = New-Object Microsoft.Exchange.WebServices.Data.ItemView(2, 0, [Microsoft.Exchange.Webservices.Data.OffsetBasePoint]::Beginning)
$itemViewForwardRule.PropertySet = New-Object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::IdOnly, [Microsoft.Exchange.WebServices.Data.ItemSchema]::ItemClass, [Microsoft.Exchange.WebServices.Data.ItemSchema]::Subject)
$itemViewForwardRule.Traversal   = [Microsoft.Exchange.WebServices.Data.ItemTraversal]::Associated

# Properties for Hidden Delegate Forwarding Rule
$PID_TAG_RULE_MSG_PROVIDER    = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x65EB,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String)

# Property Set for Delegate Forward Rule
$propertySetForwardRule = New-Object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::IdOnly, $PID_TAG_RULE_MSG_PROVIDER)

$findResults = $service.FindItems([Microsoft.Exchange.Webservices.Data.WellKnownFolderName]::Inbox, $searchFilterForwardRule, $itemViewForwardRule)
$forwardRuleExists = $false

If ($findResults.TotalCount -lt 1) {
    Write-VPSALog "Failed to find forwarding rule" "Error"
} Else {
    Foreach ($item in $findResults.Items) {
        $item.Load($propertySetForwardRule)

        If ($item.ExtendedProperties.Count -eq 1) {
            If ($item.ExtendedProperties[0].Value -eq "Schedule+ EMS Interface") {
                $forwardRuleExists = $true
                If ($pscmdlet.ShouldProcess($mailbox.Name,"Clearing Delegate Forward Rule")) {
                    $result = $item.Delete([Microsoft.Exchange.WebServices.Data.DeleteMode]::HardDelete)
                    $result
                } # Terminate WhatIf
            } # Terminate If - Correct Message
        } # Terminate If - Has Extended Properties
    } # Terminate ForEach            
} # Terminate If - Message Count

Thank you for any and all help!

-Adam


Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>