Getting some extra information about Teams federated users using PowerShell

Published on Monday, December 20, 2021

Last update: 27th of January - 2022 Added TFL support.


Inspired by my friend's Alexander Holmeset excellent blog post: Microsoft Teams Speed Dial Contacts Provisioning, I decided to investigate some other API calls made by the Teams client (as Alexander explains, easier to see using Teams web and activating browser's developer tools) and I was interested in one in particular, a request that is made when starting a new chat with external contacts, other tenants or Skype consumer.

I said, let's see how it discovers those contacts, just for fun or learning purposes, but I discovered more information is outputted than what the end user actually sees.

Useful information?

The URL that we will be querying is:[sip_uri]/externalsearchv3

If I use it to query another Teams tenant user information:

tenantId          : ceffd5d3-edcb-482e-a7ed-3ecedfe5519c
isShortProfile    : False
accountEnabled    : True
featureSettings   : @{coExistenceMode=TeamsOnly}
userPrincipalName :
givenName         :
surname           :
email             :
displayName       : Freddie Mercury
type              : Federated
mri               : 8:orgid:87da1b0b-e2a5-4964-9fcc-70bf0a186fe0
objectId          : 87da1b0b-e2a5-4964-9fcc-70bf0a186fe0

And yes, we can even know if the other party is in TeamsOnly or in Islands mode:

featureSettings   : @{coExistenceMode=Islands}

This is another example, a company that does not have tenancy but Skype For Business on-premises:

tenantId          : ac23bebc-10b0-4f0f-bae2-48b14c65af41
isShortProfile    : False
accountEnabled    : True
featureSettings   : @{coExistenceMode=Unknown}
userPrincipalName :
givenName         :
surname           :
email             :
displayName       :
type              : Federated
mri               : 8:sfb:e1c75ab3-bc2d-4733-ba24-c4186f48d1d0
objectId          : e1c75ab3-bc2d-4733-ba24-c4186f48d1d0

See how the mri now says sfb?

also a Skype (consumer) user:

skypeId           : megan.bowen
city              : Ciudad Autonoma de Buenos Aires
state             : Buenos Aires
country           : Argentina
avatarUrl         :
isShortProfile    : False
accountEnabled    : True
userPrincipalName :
email             :
displayName       : megan bowen
type              : SkypeConsumer
mri               : 8:megan.bowen

That is more information that I was expecting... :)

Is this useful? I do not exactly know, but I decided to share, maybe an administrator receives a call saying that the CEO is unable to communicate with another external user, you get the SIP URI of this user and you can, using this script understand if at least at federation level everything is how it supposed to be.

Also, if you are a heavy Teams user/Administrator/Consultant you already received the "Due to organization policy changes..." message, and I think this could help troubleshoot that and other federation scenarios.

The Script

Here is the script, I basically modified the great output of "Copy as PowerShell" feature of Edge's developer tool, as I see this more as learning purposes, I did not put much effort into it, there is a lot of room to improve it. Credits also to the great module AADInternals to get the required tokens (Teams token and x-skypetoken)

$userToSearch="" #Replace this with the other party's SIP URI you want to search more information for


Import-Module AADInternals

$user = "" #Replace this with your tenant's username
$password = "P@ssw0rd" #And your password
$secpwd = ConvertTo-SecureString $password -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ($user,$secpwd)

$token = Get-AADIntAccessTokenForTeams -Credentials $cred

$skypeToken = Get-AADIntSkypeToken -AccessToken $token

$Result=Invoke-WebRequest -UseBasicParsing -Uri $finalUrl `
-Headers @{
  "sec-ch-ua"="`" Not A;Brand`";v=`"99`", `"Chromium`";v=`"96`", `"Microsoft Edge`";v=`"96`""
  "authorization"="Bearer $token"
  "accept"="application/json, text/plain, */*"
  "accept-encoding"="gzip, deflate, br"
  ConvertFrom-Json -InputObject $result.Content

comments powered by Disqus