简体   繁体   English

通过非交互式 powershell 脚本连接到 Microsoft Teams

[英]Connecting to Microsoft Teams through non-interactive powershell script

I am trying to write an azure function in PowerShell to connect to a Microsoft Teams account:我正在尝试在 PowerShell 中编写 azure function 以连接到 Microsoft Teams 帐户:

using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)

# Write to the Azure Functions log stream.
Write-Host "Running teams account setup."

[string]$userName = 'xxx'
[string]$userPassword = 'xxx'
[securestring]$secStringPassword = ConvertTo-SecureString $userPassword -AsPlainText -Force
Write-Host ($secStringPassword | Format-Table | Out-String)
[pscredential]$credentials = New-Object System.Management.Automation.PSCredential ($userName, $secStringPassword)
Write-Host ($credentials | Format-Table | Out-String)
Connect-MicrosoftTeams -Credential $credentials

The error message I'm getting is essentially: ERROR: password_required_for_managed_user: Password is required for managed user我收到的错误消息本质上是: ERROR: password_required_for_managed_user: Password is required for managed user

I read that it might be necessary to replace -Credentials with -Identity , but I can't find any documentation on how to implement that.我读到可能有必要将-Credentials替换为-Identity ,但我找不到任何关于如何实现它的文档。

Just noticed that you are using Azure Function, I am not quite sure the root reason here, but I did some test on my side and the PowerShell function with code below works for me perfectly: Just noticed that you are using Azure Function, I am not quite sure the root reason here, but I did some test on my side and the PowerShell function with code below works for me perfectly:

using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)

$username = "<user Name>"
$passwd = "<PassWord>"

$secpasswd = ConvertTo-SecureString -String $passwd -AsPlainText -Force
$cred = New-Object Management.Automation.PSCredential ($username, $secpasswd)
Connect-MicrosoftTeams -Credential $cred

#try to get a team name to test if connect to teams successfully
$team = get-team -groupID '0d06e74e-08e0-4ef6-9bb5-3113ca735407'
$body = $team.DisplayName


# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = [HttpStatusCode]::OK
    Body = $body
})

Content of requirements.psd1 : requirements.psd1的内容:

@{
    # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. 
    'Az' = '5.*'
    'MicrosoftTeams' = '1.1.9-preview'
}

Test result:测试结果:

在此处输入图像描述 在此处输入图像描述

Azure function utilize the Powershell core. Azure function 使用 Powershell 内核。

Looks like there is a known issue with regards to the Powershell core which has been reported to the product group and it is already worked.看起来有一个关于 Powershell 内核的已知问题,该问题已报告给产品组并且已经正常工作。

Reference: https://github.com/MicrosoftDocs/office-docs-powershell/issues/5950参考: https://github.com/MicrosoftDocs/office-docs-powershell/issues/5950

Reading further, I don't see ETA on this.进一步阅读,我没有看到 ETA。 The thread is expected to be updated once there is a fix.一旦有修复,该线程预计将被更新。

Coming back to the -identity , it is just a switch parameter (you need not pass anything) which logs in using managed service identity in the current environment.回到-identity ,它只是一个开关参数(您无需传递任何内容),它在当前环境中使用托管服务身份登录。 I doubt this might be applicable in your case.我怀疑这可能适用于您的情况。 The below would be the implementation if you would like to try.如果您想尝试,以下将是实现。

Connect-MicrosoftTeams -Identity

To solve this issue, we have a third option of storing encrypted credentials to a file on the computer.为了解决这个问题,我们有第三种选择,将加密的凭据存储到计算机上的文件中。 The PowerShell script uses the encrypted password from the file to create a credential object. PowerShell 脚本使用文件中的加密密码创建凭证 object。 please go through below links.请通过以下链接 go。 link1 Link2 链接1 链接2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Powershell 中用于 Key Vault 的非交互式登录 - non-interactive login in Powershell for Key Vault 带有MFA的Microsoft Partner Center API基于非交互用户的授权 - Microsoft Partner Center API non-interactive user based authorization with MFA 如何使用Powershell执行非交互式MFA登录到Azure订阅 - How to perform a Non-Interactive MFA Login to Azure Subscription using Powershell 在非交互环境中认证和使用 Firebase - Authenticate and use Firebase in non-interactive environments Connect-MsolService 非交互式 - Connect-MsolService non-interactive Azure CLI 无 GUI 虚拟机中的非交互式登录 - Azure CLI non-interactive login in GUIless VM WebAPI使用用户名和密码对Azure AD进行非交互式身份验证 - WebAPI Non-interactive authenticating to Azure AD using username & password 如何使用非交互式身份验证连接到Power BI API? - how to connect to Power BI API using non-interactive authentication? 如何在使用Azure Webjobs和计划部署Web项目时启用非交互式身份验证? - How to enable non-interactive authentication when deploying Web project with Azure Webjobs and schedules? 如何将 MailKit 与 IMAP 用于 Exchange 与 OAuth2 用于守护程序/非交互式应用程序 - How to use MailKit with IMAP for Exchange with OAuth2 for daemon / non-interactive apps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM