TransWikia.com

Pick an account after Connect-MicrosoftTeams

Stack Overflow Asked by mauek unak on November 4, 2021

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

4 Answers

At the end I used other module 'AzureAD' and command 'Add-AzureADGroupMember':

# 'password' | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString $Password = "01000000d08c9..." | ConvertTo-SecureString

$Credentials = (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "[email protected]", $Password)

Connect-AzureAD -Credential $Credentials

$AZ_USER=Get-AzureADUser -Filter "UserPrincipalName eq '[email protected]'"

$AZ_GROUP=Get-AzureADGroup -Filter "DisplayName eq 'teams_name'"

Add-AzureADGroupMember -ObjectId $AZ_GROUP.ObjectId -RefObjectId $AZ_USER.ObjectId

then I have to wait couple hours until Active Directory and Teams got synchronized and users were added to AD groups / Teams teams. It's not ideal, but it works with saved credentials and with no user interaction.

Answered by mauek unak on November 4, 2021

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

See the discussion here

Answered by Theo on November 4, 2021

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

Answered by Luke Williams on November 4, 2021

Answered by baswijdenesdotcom on November 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP