I am trying to use Azure RunBook with PowerShell to manage the call forwarding status for Teams users. I use an Azure app that has (I believe) all required Graph API permissions:
And is also set as Teams Administrator.
Important note: I'm running it in 5.1 version, the 7.1 preview kept saying that I have incorrect access rights, which was a bull
The Runbook PowerShell code is as follow:
#Import Modules
Import-Module MSAL.PS
Import-Module MicrosoftTeams
#Clear Tokencache
Clear-MsalTokenCache
#Variables
$TenantId = "TenantID of my app"
$ClientID = "ClientId of my app" #DemoTeamsPS app
$ClientSecret ="generated secret"
$graphtokenBody = @{
Grant_Type = "client_credentials"
Scope = "https://graph.microsoft.com/.default"
Client_Id = $ClientID
Client_Secret = $ClientSecret
}
$graphToken = Invoke-RestMethod -Uri
"https://login.microsoftonline.com/$TenantID/oauth2/v2.0/token" -Method POST -Body
$graphtokenBody | Select-Object -ExpandProperty Access_Token
$teamstokenBody = @{
Grant_Type = "client_credentials"
Scope = "48ac35b8-9aa8-4d74-927d-1f4a14a0b239/.default"
Client_Id = $ClientID
Client_Secret = $ClientSecret
}
$teamsToken = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$TenantID/oauth2/v2.0/token" -Method POST -Body $teamstokenBody | Select-Object -ExpandProperty Access_Token
Connect-MicrosoftTeams -AccessTokens @("$graphToken", "$teamsToken")
Get-CsOnlineUser -Identity me@myOrganisation.com | fl *Ent*,*host*,*voice*, *um*
Up to this line, everything works fine, the test pane returns my details. However, I am trying to change the call forwarding rules. Hence the two lines:
Set-CsUserCallingSettings -Identity me@myOrganisation.com -IsUnansweredEnabled $FALSE
Set-CsUserCallingSettings -Identity me@myOrganisation.com -IsForwardingEnabled $true -ForwardingType Immediate -ForwardingTargetType SingleTarget -ForwardingTarget "+1234567891"
But this returns an error "The stream was already consumed. It cannot be read again" (twice actually, one for each line).
Do you have any ideas?
Note: using
Get-CsUserCallingSettings -Identity me@mycompany.com
returns the same error