Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pick an account after Connect-MicrosoftTeams

I'd like to write a PowerShell script which will update Teams members from input list/object. However if I run Connect-MicrosoftTeams command (to authenticate/connect to cloud service) for the first time I am asked to pick an account to use for login. This is an issue since I would like this script to be run as scheduled job. Is there a way how to avoid this when running Connect-MicrosoftTeams command ? Commands I am using:

$credential = Get-Credential

Connect-MicrosoftTeams -Credential $credential

Connect-MicrosoftTeams credentials window

I tried to use "-AccountId "[email protected]" but that didn't help. Of course later I will change Get-Credential to username and encrypted password

EDIT

If I run Connect-MicrosoftTeams -Credential $credential on other computer, where I've never been logged in with my account, instead of "Pick an account" window, I get credential window for username and password: Connect-MicrosoftTeams credentials window

like image 728
mauek unak Avatar asked Oct 25 '25 02:10

mauek unak


2 Answers

As commented, this is certainly a dissapointment, but Single-Sign-On cannot be enabled in Microsoft Teams.

See the discussion here

like image 91
Theo Avatar answered Oct 26 '25 19:10

Theo


This should achieve what you're trying to do.

Credits to: https://www.jaapbrasser.com/quickly-and-securely-storing-your-credentials-powershell/

Save Credentials

$Credential = Get-Credential
$Credential | Export-CliXml -Path "<File path/name to save credentials"

Connect using saved credentials through MS Teams PowerShell

$Credential = Import-CliXml -Path "<path of exported credential>"
Connect-MicrosoftTeams -AccountId "<email>" -Credential $Credential
like image 22
Luke Williams Avatar answered Oct 26 '25 17:10

Luke Williams