Script Repository


Connect to Microsoft Teams

April 23, 2021
1064

The script establishes connection to Microsoft Teams. For the script to work you need to install a certificate for connection to Microsoft Teams on the computer where Adaxes service runs. To do so:

  1. Create a certificate using the New-PnPAzureCertificate cmdlet.
  2. Assign the certificate to the Azure application whose credentials were used to register your Microsoft 365 tenant in Adaxes.
  3. Grant Azure application access to Microsoft Teams.
  4. Install the certificate on the computer where Adaxes service runs.

Also, the script requires the MicrosoftTeamsPowerShell module to be installed on the computer where Adaxes service runs.

Parameters:

Edit Remove
PowerShell
$certificateThumbprint = "9BCE7405DD63FD8DE7486FDD32D111667197BB8E" # TODO: modify me

# Connect to Microsoft Teams
$tenant = $Context.CloudServices.GetO365Tenant()
$credential = $tenant.GetCredential()

try
{
    Connect-MicrosoftTeams -TenantId $tenant.TenantId -CertificateThumbprint $certificateThumbprint -applicationid $credential.AppId
    
    $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 ( 4 )
avatar
TJ Umredkar
Apr 26, 2021
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.
avatar
Support
Apr 28, 2021
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.
  1. Sign in to Azure AD portal.
  2. Navigate to and open the App registration service.
  3. Click the application whose credentials were used to register the Microsoft 365 tenant in Adaxes.
  4. Click Certificates & secrets.
  5. In the Certificates section, click Upload certificate.
  6. Select the certificate you generated to connect to Microsoft Teams.
  7. Click Add.


>-Grant Azure application access to Microsoft Teams.
  1. Sign in to Azure AD portal.
  2. Navigate to and open the App registration service.
  3. Click the application whose credentials were used to register the Microsoft 365 tenant in Adaxes.
  4. Click API permissions.
  5. Click Add a permission.
  6. Click Microsoft Graph.
  7. Click Application permissions.
  8. Select the permissions required to accomplish tasks in your script.
  9. Click Add permissions.
  10. Click Grant admin consent for <tenant name>. 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.
avatar
itsupport
Aug 26, 2021
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
avatar
Support
Aug 27, 2021
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.
avatar
itsupport
Aug 30, 2021
works great!!! thank you so much!
Leave a comment

Related Scripts