I asked this question last year, but have just dealt with running the commands manually since as I was unable to work out a solution.
https://www.adaxes.com/questions/10506/how-to-connect-to-ms-teams-using-adaxes
It seems this is a common question as it was asked by someone else a short time later - https://www.adaxes.com/questions/10722/is-there-a-way-to-connect-to-ms-teams-via-adaxes-powershell
Has anyone found a proper way to connect to Teams powershell and run basic commands?
I have found this script provided two days ago - https://www.adaxes.com/questions/11982/is-there-a-way-to-add-users-to-ms-teams-groups-from-adaxes
and tried to modify it, but no luck so far - I get an error that the user does not have a teams account when manually running the script, and when running the scheduled task nothing happens.
Initially I got an error (didn't realise you had to specify the account to run the task as, even though it's the same as the service account that runs adaxes, seems a bit backwards!) and now the task runs, but does not seem to work. There is no logs as to what the script achieves.
Here is the script as I have made it. I have set it up as a scheduled task, and want it to run after a new user has been created - I can flesh it out later on and make it only run on users with some attribute set somewhere, but for now I just want it to run at all (and work!)
For now I have set it to run over a test OU, and both users in it are definitely synced up to Office 365.
$username = $Context.RunAs.UserName
$password = $Context.RunAs.Password | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object System.Management.Automation.PsCredential($username, $password)
try
{
$objectId = ([Guid]$Context.TargetObject.Get("adm-O365ObjectId")).ToString()
}
catch
{
return
}
try
{
Connect-MicrosoftTeams -Credential $credential
$user = Get-CsOnlineUser -Filter "Identity -eq '$objectId'"
if ($NULL -eq $user)
{
$Context.LogMessage("The user does not have a Microsoft Teams account", "Information")
return
}
Set-CsUser -Identity $user -EnterpriseVoiceEnabled $true -HostedVoiceMail $true
Grant-CsOnlineVoiceRoutingPolicy -Identity $user -PolicyName “Worldwide”
Grant-CsCallingLineIdentity -Identity $user -PolicyName "No DDI Auckland"
}
finally
{
Disconnect-MicrosoftTeams
}
I'm running Adaxes 2021.1, Version 3.14.18804.0, and I believe I've got Teams powershell 2.3.1 installed
I attempted to follow Adaxes's other suggestion here to swap our service account to an Application Account - https://www.adaxes.com/script-repository/connect-to-microsoft-teams-s615.htm
However they do not specify what permissions to grant here:
"Click Add a permission.
Click Microsoft Graph.
Click Application permissions.
Select the permissions required to accomplish tasks in your script.
Click Add permissions
"
So I have reverted to the service account setup, as I am desktop support not Azure Magician and do not know what API's teams falls under.