@Daniel Becker ,
As we are mainly responsible for general issue of Microsoft Teams, your question which is more related to script is not in our scope. Thanks for your understanding.
The following script is for your reference. I have tested it in my lab. It works well.
$User = "xxx@contoso.com"
$PassWord = ConvertTo-SecureString -String "YourPassword" -AsPlainText -Force
$UserCredential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $User, $PassWord
import-module microsoftteams
Connect-MicrosoftTeams -Credential $UserCredential -AccountId $User
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.