Skip to content

Instantly share code, notes, and snippets.

@AlexanderHolmeset
Last active July 11, 2024 20:56
Show Gist options
  • Save AlexanderHolmeset/7a3006ea3b3030baaf91da09a1de6e07 to your computer and use it in GitHub Desktop.
Save AlexanderHolmeset/7a3006ea3b3030baaf91da09a1de6e07 to your computer and use it in GitHub Desktop.
#Updated for Teams v2!
#Blog: Alexholmeset.blog
#Import the Azure AD Internals module.
Import-Module AADInternals
#Users to process
$Users = import-csv c:\temp\users.csv
foreach($user in $users){
$password = ConvertTo-SecureString $user.password -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList ($($user.upn), $password)
#Get the Teams token for user curently beeing processed.
$token = Get-AADIntAccessTokenForTeams -Credentials $cred
#URL to buddylists.
#The url is difrent depending on theregion your tenant is hosted in. This URL is from Europe, therefore EMEA in the URL.
#Example from the US is amer-03. See blogpost above for detqils on fidning this url.
$URL = "https://teams.microsoft.com/api/mt/emea/beta/contactsv3/"
$header = @{Authorization = "Bearer $token"}
#Number to Add. MRI is the phonenumber of the contact, same as phone property. If contact to be added is a internal user, add the request like this:
#{"mri":"8:orgid:18c4a91b-4fa9-4fbd-ab1c-b39465d81baf","defaultEmail":"[email protected]","names":[{"displayName":"Admin","first":"Admin","last":"Admin","pronunciation":{}}],"emails":[{"address":"[email protected]","type":"Main"}],"phones":[{"number":" ","type":"Business"}],"addresses":[],"notes":[],"anniversaries":[],"relationships":[],"websites":[],"webAccounts":[{"userId":"[email protected]"},{"userId":"OID:18c4a91b-4fa9-4fbd-ab1c-b39465d81baf@29594fb0-53f2-490c-a1be-8b2cca824805","service":{"name":"Profile"},"source":{"type":"Profile"}}],"tags":[],"systemTags":[{"displayName":"Favorites"}]}
#Orgid is the obejct id of the user you are adding, in Microsoft Entra ID. Under Userid in this request after OID its userobjectid@tenantid.
$payload1 = @'
{"mri":"4:+471234","names":[{"first":"Helpdesk","pronunciation":{}}],"emails":[],"phones":[{"number":"1234","type":"Business"}],"addresses":[],"positions":[],"notes":[],"anniversaries":[],"relationships":[],"websites":[],"webAccounts":[],"tags":[],"systemTags":[{"displayName":"Favorites"}]}
'@
#Add phonenumber 1 to Speed Dial list.
Invoke-RestMethod -Uri $URL -Body $payload1 -Method POST -Headers $header -ContentType "application/json"
$payload2 = @'
{"mri":"4:554455","names":[{"first":"Contoso","pronunciation":{}}],"emails":[],"phones":[{"number":"554455","type":"Business"}],"addresses":[],"positions":[],"notes":[],"anniversaries":[],"relationships":[],"websites":[],"webAccounts":[],"tags":[],"systemTags":[{"displayName":"Favorites"}]}
'@
#Add phonenumber 2 to Speed Dial list.
Invoke-RestMethod -Uri $URL -Body $payload2 -Method POST -Headers $header -ContentType "application/json"
}
@ColWhackaMole
Copy link

ColWhackaMole commented Nov 12, 2023

Does this code work for anyone? I'm getting 404 not found at ((Invoke-RestMethod -Uri $URL

*Edit: I found the error and fixed it. It is in my fork @ https://gist.github.com/ColWhackaMole/b4f9130f49494eccfa1b5f3f8a398ba9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment