在 Connect-MicrosoftTeams 之后选择一个帐户

Pick an account after Connect-MicrosoftTeams

我想编写一个 PowerShell 脚本,它将根据输入 list/object 更新 Teams 成员。但是,如果我第一次使用 运行 Connect-MicrosoftTeams 命令(authenticate/connect 到云服务),系统会要求我选择一个用于登录的帐户。这是一个问题,因为我希望此脚本作为预定作业 运行。 运行ning Connect-MicrosoftTeams 命令时有没有办法避免这种情况?我正在使用的命令:

$credential = Get-Credential

Connect-MicrosoftTeams -Credential $credential

我试过用"-AccountId "email@address.com"没用,当然后面我会把Get-Credential改成username和encrypted password

编辑

如果我 运行 Connect-MicrosoftTeams -Credential $credential 在另一台计算机上,我从未使用我的帐户登录过,而不是“选择一个帐户” window,我得到凭据 window 用户名和密码:

为此,我总是使用 Jaap Brasser 的这个:

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

这应该可以实现您的目标。

感谢:https://www.jaapbrasser.com/quickly-and-securely-storing-your-credentials-powershell/

保存凭据

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

通过 MS Teams PowerShell 使用保存的凭据进行连接

$Credential = Import-CliXml -Path "<path of exported credential>"
Connect-MicrosoftTeams -AccountId "<email>" -Credential $Credential

如评论所述,这当然令人失望,但无法在 Microsoft Teams 中启用单点登录。

the discussion here

最后我使用了其他模块 'AzureAD' 和命令 'Add-AzureADGroupMember':

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

$Credentials = (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "user@domain.com", $Password)

Connect-AzureAD -Credential $Credentials

$AZ_USER=Get-AzureADUser -Filter "UserPrincipalName eq 'user@domain.com'"

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

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

然后我必须等待几个小时,直到 Active Directory 和 Teams 同步并且用户被添加到 AD 组/Teams 团队。这并不理想,但它适用于保存的凭据并且无需用户交互。