Issue converting EntryId to EwsId, it gives ImmutableId

43 Views Asked by At

I'm following tutorial and succesfully run the convert from EntryId to EwsId, using either EWS or GraphAPI (result is the same).

But the problem is that while I can convert from EntryId to RestId and find it back with Graph, converting from EntryId to EwsId and then Binding gives the error "This protocol does not support ImmutableIds".

$64decoded = [System.BitConverter]::ToString([System.Convert]::FromBase64String($ItemId)).Replace("-", "")
        write-host $64decoded
        $HexId = new-object Microsoft.Exchange.WebServices.Data.AlternateId([Microsoft.Exchange.WebServices.Data.IdFormat]::HexEntryId, $64decoded, $email)
        $Converted = $service.ConvertId($HexId, [Microsoft.Exchange.WebServices.Data.IdFormat]::EwsId)
        $idObject = new-object Microsoft.Exchange.WebServices.Data.ItemId($Converted.UniqueId)

Or with Graph using the library:

$sourceID = ($sourceId -replace "\+","-") -replace "/","_"
$countToReplace = ($sourceID.ToCharArray() | ? {$_ -eq "="}).Count
$sourceID = $sourceID.TrimEnd("=") + $countToReplace

$body = @{
"inputIds"= @($sourceID)
"sourceIdType"= "entryId"
"targetIdType"= "$TargetFormat"
} | ConvertTo-Json

$ConvertResult =  Invoke-MgTranslateUserExchangeId -UserId $UserId -BodyParameter $body

Definitely the result is not an EWSID, it looks like that:

  1. SourceId: AAAAAB2EAx########################################gAAKDC/7wAAA==
  2. TargetId: AAkALg#############################################i8zOVOAAAAAe9FwAA

What am I missing?

Thank you

EDIT:

Following exactly this blog commands, here are the output from the first line ID:

https://www.michev.info/blog/post/2744/converting-item-and-folder-ids-via-the-graph-api

enter image description here

As we can see, the EWSId does not look at all like a full EWS Id. I even specied IsArchive = $true on the $aiItem.

1

There are 1 best solutions below

2
Glen Scales On

From what you posted in the result anything starting with AAkALg is a immutableId https://learn.microsoft.com/en-us/graph/outlook-immutable-id the "AAkALg" decodes to a Flag that tells Exchange this which is why it's the same on every request. You should be able to take that Id and then translate it to a ewsid eg

{
    "inputIds": [
        "AAkALgAAAAAAHYQDEapmEc2byACqAC-EWg0AdRBH-RjqME2dQLFCi6wg0AAIdd8qMwAA"
    ],
    "sourceIdType": "restImmutableEntryId",
    "targetIdType": "ewsId"
}

There where previously bugs in Invoke-MgTranslateUserExchangeId so i would probably try using Invoke-MgGraphRequest to see if you get a different result eg

    $ConvertRequest = @"
{
    "inputIds" : [
      "$FolderIdToConvert"
    ],
    "sourceIdType": "entryId",
    "targetIdType": "ewsId"
  }
"@

    $ConvertResult = Invoke-MgGraphRequest -Method POST -Uri https://graph.microsoft.com/v1.0/me/translateExchangeIds -Body $ConvertRequest