Skip to content

Instantly share code, notes, and snippets.

@AlexanderHolmeset
Last active November 12, 2023 18:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AlexanderHolmeset/7a3006ea3b3030baaf91da09a1de6e07 to your computer and use it in GitHub Desktop.
Save AlexanderHolmeset/7a3006ea3b3030baaf91da09a1de6e07 to your computer and use it in GitHub Desktop.
#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/contacts/buddylist/"
$header = @{Authorization = "Bearer $token"}
#Get id of the Speed Dial list.
$ListID = ((Invoke-RestMethod -Uri $URL -Method GET -Headers $header -ContentType "application/json").value | Where-Object{$_.displayname -like "Favorites"}).id
#URL for the Speed Dial list.
$URL = "https://teams.microsoft.com/api/mt/emea/beta/contacts/buddylist/$ListID/managebuddies?migrationRequested=true&federatedContactsSupported=true"
#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:
#{"add":[{"mri":"8:orgid:18c4a91b-4fa9-4fbd-ab1c-b39465d81baf","displayName":"Admin","isFederated":false,"email":"brumunddal@alexholmeset.onmicrosoft.com"}]}
#To find the org id, run this command and look for it in a users buddies list:
#(Invoke-RestMethod -Uri $URL -Method GET -Headers $header -ContentType "application/json").value
$payload1 = @'
{"add":[{"mri":"4:123456789","displayName":"Helpdesk","phone":"123456789","companyName":"Contoso","jobTitle":""}]}
'@
#Add phonenumber 1 to Speed Dial list.
Invoke-RestMethod -Uri $URL -Body $payload1 -Method POST -Headers $header -ContentType "application/json"
$payload2 = @'
{"add":[{"mri":"4:987654321","displayName":"Reception","phone":"987654321","companyName":"Contoso","jobTitle":""}]}
'@
#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