[英]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.