Script to connect MS Teams

Sometime you may want to avoid entering user-name and password every time. Below is the small script you can use it to connect to MS Teams. Last line of the below code is just to change the PowerShell title. This will helpful in case you are connecting multiple environment. It will be easy to identify which PowerShell window belongs to which tenant. Title will be set temporarily, when we close the console and open it again, the title will be set to the default.

#Specify UserName and Password
$UserName = "Admin@cloudmechanics.in"
$PassWord = ConvertTo-SecureString -String "Password" -AsPlainText -Force
 
#Create a Credential object
$Cred = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $UserName, $PassWord
 
#Connect to Microsoft Teams with specified credentials

Connect-MicrosoftTeams -Credential $Cred

# Below cmdlts will add Cloud-Mechanics to PowerShell Title
$host.UI.RawUI.WindowTitle = "Cloud-Mechanics"
This entry was posted in MS Teams, Powershell. Bookmark the permalink.

2 Responses to Script to connect MS Teams

  1. Rahul says:

    Quick and small. But I am not able to connect account with MFA enabled. Any suggestion.

    • DV says:

      Hi Rahul, For MFA we need to make use of connect-microsoftTeams onto powershell. We cant script it currently. Best you can do is make use of -AccountId parameter to supply the user ID.

Leave a Reply

Your email address will not be published.