Script repository
The script establishes connection to Microsoft Teams. To execute the script, create a business rule, custom command or scheduled task configured for the required object type.
To use the script, install the MicrosoftTeamsPowerShell module on the computer where the service runs.
# Get access tokens.
$graphToken = $Context.CloudServices.GetAzureAuthAccessToken("https://graph.microsoft.com")
$teamsToken = $Context.CloudServices.GetAzureAuthAccessToken("48ac35b8-9aa8-4d74-927d-1f4a14a0b239")
# Connect to Microsoft Teams.
try
{
Connect-MicrosoftTeams -AccessTokens @($graphToken, $teamsToken)
$team = Get-Team -DisplayName "My Team" # TODO: replace with the code you need to execute
}
finally
{
# Close the connection and release resources.
Disconnect-MicrosoftTeams -Confirm:$False
}
Comments 7
You must be signed in to comment.
TJ Umredkar
Hi, would you please provide more instructions on how to do the following steps:
-Assign the certificate to the Azure application whose credentials were used to register your Microsoft 365 tenant in Adaxes.
-Grant Azure application access to Microsoft Teams.
-Install the certificate on the computer where Adaxes service runs.
Support
Please, note that the steps are required to make it possible to connect to Microsoft Teams using the Connect-MicrosoftTeams cmdlet. These are Microsoft requirements and they are not related to Adaxes directly. Should you have any issues accomplishing the steps, we suggest considering possibility to contact Microsoft Support for further troubleshooting. However, below you can find an approximate list of steps you should take to accomplish the required configuration.
>-Assign the certificate to the Azure application whose credentials were used to register your Microsoft 365 tenant in Adaxes.
Sign in to Azure AD portal.
Navigate to and open the App registration service.
Click the application whose credentials were used to register the Microsoft 365 tenant in Adaxes.
Click Certificates & secrets.
In the Certificates section, click Upload certificate.
Select the certificate you generated to connect to Microsoft Teams.
Click Add.
>-Grant Azure application access to Microsoft Teams.
Sign in to Azure AD portal.
Navigate to and open the App registration service.
Click the application whose credentials were used to register the Microsoft 365 tenant in Adaxes.
Click API permissions.
Click Add a permission.
Click Microsoft Graph.
Click Application permissions.
Select the permissions required to accomplish tasks in your script.
Click Add permissions.
Click Grant admin consent for . Admin consent is required to make the added permissions effective.
>-Install the certificate on the computer where Adaxes service runs.
On the computer where Adaxes service is installed, right-click the certificate file and then click Install Certificate. Follow the instructions in the Certificate Import Wizard.
itsupport
Connect-MicrosoftTeams version 2.5.0 not working anymore :-(
Version 2.3.2 works but non cs* commands possible.
Managing teams with Adaxes withouth interactive login seems impossible for now
Support
Hello,
> Connect-MicrosoftTeams version 2.5.0 not working anymore
Yes, that is correct and there is currently no related documentation from Microsoft.
>Version 2.3.2 works but non cs* commands possible.
Yes, the script works fine with the module version 2.3.2.
>Managing teams with Adaxes withouth interactive login seems impossible for now
That is not correct. You can specify user account credentials in the Run as section of the Run a program or PowerShell script action and then use them in your script. For details, see section Running the script as a specific user of the following SDK article: https://adaxes.com/sdk/ServerSideScripting/#running-the-script-as-a-specific-user.
itsupport
works great!!! thank you so much!
Boris
I have used the Script above to connect to MS Teams with Powershell 5 and
Connect-MicrosoftTeams version Version 2.3.2
After the Update to Adaxes 2025.1 this is not working anymore, because Powershell 7 does not support this.
Any workarrounds to make MS Teams number and dialplan assignments with Adaxes 2025.1
Thanks
Support
Hello Boris,
The script works just fine in Adaxes 2025.1. You only need to make sure that a version of the MicrosoftTeams PowerShell module supporting PowerShell 7 is installed on the computers where Adaxes service runs. Make sure for it to be the only version by uninstalling the rest. Unfortunately, there is no specifics in Microsoft documentation as to the versions of the module that support PowerShell 7, but we tested with version 6.9.0 and it worked without any issues.