0

我想通过使用由 Azure 队列触发的 azure 函数来创建团队。不幸的是,当我运行代码时,它在 Azure 函数中不起作用。

我在想。有没有办法在 Azure Function 中使用 PowerShell 创建 Microsoft Team?

Import-module MicrosoftTeams
$group = New-Team -MailNickname "teamTitle" -displayname "teamTitle" -Visibility "private"
Add-TeamUser -GroupId $group.GroupId -User "user@etc.com"
New-TeamChannel -GroupId $group.GroupId -DisplayName "General"

在当地工作。在 Azure 函数中不起作用。

波纹管我得到的错误:

ERROR: Import-Module : The specified module 'MicrosoftTeams' was not loaded because no valid
module file was found in any module directory. At D:\home\site\wwwroot\CreateTeam\run.ps1:3
char:1 + Import-Module MicrosoftTeams +  [...]

谢谢

4

3 回答 3

2

根据错误消息,您的函数应用没有安装 MicrosoftTeams 模块。您需要在requirements.psd1文件中包含对此模块的引用(有关更多详细信息,请参阅https://docs.microsoft.com/azure/azure-functions/functions-reference-powershell#dependency-management)。

于 2020-07-27T17:06:56.303 回答
1

目前此模块尚未原生集成到 powershell 下的 azure 函数中

要查看所有可用的包,请进入 App Service -> Advanced Tools -> DebugConsole -> Powershell 并运行:

Write-Output ‘Getting PowerShell Module’
$result = Get-Module -ListAvailable |
Select-Object Name, Version, ModuleBase |
Sort-Object -Property Name |
Format-Table -wrap |
Out-String
Write-output `n$result

要手动添加包,需要创建一个目录“模块”与功能目录在同一级别,它们将被自动预加载。

https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-powershell步骤“函数应用级模块文件夹”)

于 2020-07-30T12:28:10.043 回答
0

模块安装后。在您的脚本中使用以下代码来自动化该过程。

$securedpassword = ConvertTo-SecureString $Password -AsPlainText -Force
$mycredentials = New-Object System.Management.Automation.PSCredential ($Username, $securedpassword )
$res = Connect-MicrosoftTeams -Credential $mycredentials
于 2020-07-29T04:43:11.000 回答