Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment