Changing Folder and ItemIds from the Change Administration Shell and Audit Log entries utilizing PowerShell and the Graph API in Change On-line

Changing Folder and ItemIds from the Change Administration Shell and Audit Log entries utilizing PowerShell and the Graph API in Change On-line

First just a little information about Change Identifiers that you could have missed (its not usually that one thing like this adjustments so its relatively thrilling)

While you entry an merchandise in an Change Mailbox retailer whether or not its OnPrem or within the Cloud you utilize the Identifier of the actual merchandise which is able to range throughout no matter API your utilizing. Eg

MAPI – PR_EntryId eg NameSpace.GetItemFromID(EntryId)
EWS –  EWSId eg EmailMessage.Bind(service,ewsid)
Relaxation –   RestId  eg https://graph.microsoft.com/v1.0/me/messages(‘restid’)

The recommendation through the years has at all times been its not a good suggestion to retailer these Id’s in one thing like a database as a result of they modify each time and Merchandise is moved. Eg if an Merchandise is moved from the Inbox to a Subfolder within the Inbox it would obtained a special Id so no matter you have got saved in your database abruptly turns into invalid and its not simple to reconcile this. Nevertheless a brand new characteristic that has appeared in Change On-line in Beta with the Graph API is immutableId’s see https://docs.microsoft.com/en-us/graph/outlook-immutable-id the concept behind that is that this Id does not change no matter which folder the merchandise is moved to (or even when its deleted). Whereas it nonetheless in Beta in the mean time it is a good characteristic to make use of going ahead in case your constructing synchronization code. Together with immutableId’s an operation to Translate Id’s between the EntryId, EWS and REST codecs is now obtainable in beta within the Graph which is nice in case your trying to Migrate your MAPI or EWS apps to make use of the Graph API https://github.com/microsoftgraph/microsoft-graph-docs/blob/grasp/api-reference/beta/api/user-translateexchangeids.md 

As Audit information are a scorching matter of debate this week with this put up from Microsoft one other Identifier format you see when utilizing the Change Administration Shell cmdlets like Get-MailboxFolderStatics is one thing like


or in an ItemId in a  AuditLog File like


With these Id’s there are only a base64 encoded model of the EntrydId with a number one and trailing byte. So to get again to the Hex model of the Entryid you may be aware of from a Mapi Editor you should utilize one thing like the next


$HexEntryId = [System.BitConverter]::ToString([Convert]::FromBase64String($_.FolderId.ToString())).Change("-","").Substring(2)  
$HexEntryId = $HexEntryId.SubString(0,($HexEntryId.Size-2))

This may flip one thing like

RgAAAAC+HN09lgYnSJDz3kt9375JBwB1EEf9GOowTZ1AsUKLrCDQAAAAAAENAAB1EEf9GOowTZ1AsUKLrCDQAALbJe1qAAAP

Into

00000000BE1CDD3D9606274890F3DE4B7DDFBE490700751047FD18EA304D9D40B1428BAC20D000000000010D0000751047FD18EA304D9D40B1428BAC20D00002DB25ED6A0000

Simply having the Id in no matter format is not a lot good until you are able to do one thing with it, so I’ve created a easy Graph script that makes use of the brand new user-translateexchangeids.md operation to assist you to translate this Id into an Id that might be useable in different Graph requests. I’ve create a primary ADAL script model an posted it right here on my GitHub https://github.com/gscales/Powershell-Scripts/blob/grasp/translateEI.ps1

A fast Demo of it in use eg Translate a RestId into an EntryId

Invoke-TranslateExchangeIds -SourceId "AQMkADczNDE4YWE..." -SourceFormat restid -TargetFormat entryid

By default the operation returns a urlsafe base64 encoded outcomes (with padding) so within the script I decode this to the HexEntryId which I discover probably the most helpful.

I’ve additionally cater for permitting you to put up a HexEntryId and the script will mechanically encode that for the operations eg


Invoke-TranslateExchangeIds -SourceHexId "00000000BE1CDD3D9606274890F3DE4B7DDFBE49..." -SourceFormat entryid -TargetFormat restid

And it additionally caters for the encoded EMS format and can strip the additional bytes and covert that eg


Invoke-TranslateExchangeIds -SourceEMSId  $_.FolderId.ToString() -SourceFormat entryid -TargetFormat restid

I’ve additionally added this to my Exch-Relaxation module which is accessible from the PowerShell Gallery and GitHub which is beneficial if you wish to do some following kind issues. eg should you wished to bind to the folder in query you can use


$folderId = Invoke-EXRTranslateExchangeIds -SourceEMSId  $_.FolderId.ToString() -SourceFormat entryid -TargetFormat restid
Get-EXRFolderFromId -FolderId $folderId

Need assistance with something I’ve talked about on this put up or want someone to jot down C#,JS, NodeJS, Azure or Lambda capabilities, Messaging DevOps or PowerShell scripts then I am obtainable now for freelance/contract or fulltime work so please drop me an Electronic mail at gscales@msgdevelop.com

Leave a Reply