powershell 是否使用translateExchangeIds将EWS StoreId(FolderID)转换为图形API restId?

db2dz4w8  于 2023-03-08  发布在  Shell
关注(0)|答案(1)|浏览(122)

是否有任何方法可以将Get-MailboxFolderStatistics返回的folderIdstoreId)转换为Microsoft图形API restId
我尝试使用users/{userId}/translateExchangeIds端点,但没有得到任何有用的结果。

users/{userId}/translateExchangeIds终结点是否支持将storeId转换为restId
有没有其他方法来翻译这个id?

szqfcxe2

szqfcxe21#

您需要自己将storeId转换为entryId,然后使用users/{userId}/translateExchangeIdsentryId转换为restId
要将storeId转换为entryId,请将folderId从base64字符串转换为十六进制字符串。然后解析entryId十六进制字符串并将entryId十六进制字符串编码为entryId

$folderId = "LgAAAADMaqNx7y87SYAkFzRBDsNkAQDBGxV/99wUQoEROcv7tgfjAAAWrAyWAAAB"

# convert from base64 to bytes
$folderIdBytes = [Convert]::FromBase64String($folderId)

# convert byte array to string, remove '-' and ignore first byte
$folderIdHexString = [System.BitConverter]::ToString($folderIdBytes).Replace('-','')
$folderIdHexStringLength = $folderIdHexString.Length

# get hex entry id string by removing first and last byte
$entryIdHexString = $folderIdHexString.SubString(2,($folderIdHexStringLength-4))

# convert to byte array - two chars represents one byte
$entryIdBytes = [byte[]]::new($entryIdHexString.Length / 2)

For($i=0; $i -lt $entryIdHexString.Length; $i+=2){
    $entryIdTwoChars = $entryIdHexString.Substring($i, 2)
    $entryIdBytes[$i/2] = [convert]::ToByte($entryIdTwoChars, 16)
}

# convert bytes to base64 string
$entryIdBase64 = [Convert]::ToBase64String($entryIdBytes)

# count how many '=' contains base64 entry id
$equalCharCount = $entryIdBase64.Length - $entryIdBase64.Replace('=','').Length

# trim '=', replace '/' with '-', replace '+' with '_' and add number of '=' at the end
$entryId = $entryIdBase64.TrimEnd('=').Replace('/','_').Replace('+','-')+$equalCharCount

将值为LgAAAADMaqNx7y87SYAkFzRBDsNkAQDBGxV/99wUQoEROcv7tgfjAAAWrAyWAAABfolderId转换为entryIdAAAAAMxqo3HvLztJgCQXNEEOw2QBAMEbFX_33BRCgRE5y_u2B-MAABasDJYAAA2
然后在调用中使用转换后的entryId

{
  "inputIds" : [
    "AAAAAMxqo3HvLztJgCQXNEEOw2QBAMEbFX_33BRCgRE5y_u2B-MAABasDJYAAA2"
  ],
  "sourceIdType": "entryId",
  "targetIdType": "restId"
}

回应

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.convertIdResult)",
    "value": [
        {
            "sourceId": "AAAAAMxqo3HvLztJgCQXNEEOw2QBAMEbFX_33BRCgRE5y_u2B-MAABasDJYAAA2",
            "targetId": "AAMkAGRkZTFiMDQxLWYzNDgtNGQ3ZS05Y2U3LWU1NWJhMTM5YTgwMAAuAAAAAADMaqNx7y87SYAkFzRBDsNkAQDBGxV-99wUQoEROcv7tgfjAAAWrAyWAAA="
        }
    ]
}

资源:
URL安全

相关问题