当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 新的 PowerShell 模块 Microsoft Teams 0.9.6 教程

作者:精品下载站 日期:2024-12-14 07:12:27 浏览:14 分类:玩电脑

新的 PowerShell 模块 Microsoft Teams 0.9.6 教程


大家好,

自从上一篇有关 Microsoft Teams 和 PowerShell 集成的文章以来已经有一段时间了。所以有一些突发新闻。团队模块现在终于可以找到所有团队,而不仅仅是团队登录用户是成员。呼呼?

另一项重大改进是您不再需要 MS Teams 许可证来进行管理。可以通过“团队管理员”来完成所有这些工作,但我们稍后会看到。

那么我们可以用这个全新的功能做什么呢?现在我们终于可以大致了解我们组织中的团队了。

首先,请安装新模块0.9.6。另请参阅 PSGallery

您可以在 ISE 或 VSCode 或普通 Powershell 控制台中执行此操作。在这个演示中,我选择了老式的 ISE。

Install-Module MicrosoftTeams -Verbose -Force

[玩转系统] 新的 PowerShell 模块 Microsoft Teams 0.9.6 教程

当然,安装后您不能直接使用该模块,因此您必须在 PowerShell 会话中导入它。所以退出很简单,只需使用 import-module cmdlet

Import-Module MicrosoftTeams -Verbose -Force

Powershell 正在导入 cmdlet 以及启动所需的所有内容。请检查您的版本是否正确!

Get-Module MicrosoftTeams

[玩转系统] 新的 PowerShell 模块 Microsoft Teams 0.9.6 教程

团队中的管理权限怎么样?

如上所述,您不需要“全局管理员”即可在团队中使用 PowerShell 执行某些操作。因此,让我们访问 O365 组织的管理中心。我亲自生成了一个全新的管理员用户,专门用于团队管理。

注意:不需要 Teams 许可证!

有关 O365 管理角色的详细信息,请参阅此链接

[玩转系统] 新的 PowerShell 模块 Microsoft Teams 0.9.6 教程

[玩转系统] 新的 PowerShell 模块 Microsoft Teams 0.9.6 教程

[玩转系统] 新的 PowerShell 模块 Microsoft Teams 0.9.6 教程

激活后,请给 azure 几秒钟的时间,返回 PowerShell 并使用新用户(或具有特权的任何其他用户)连接到 MSTeams。

以下代码仅适用于 ISE 或纯 PowerShell 控制台

$tenant = (Connect-MicrosoftTeams)
$account = ($tenant.account)
$tenantdomain = ($tenant.TenantDomain)
$host.ui.RawUI.WindowTitle = "Windows Powershell remote connection to MSTeams Tenant: $tenantdomain with account $account "


出于演示目的,我在纯 PowerShell 控制台中执行此行,但它也适用于 ISE。

[玩转系统] 新的 PowerShell 模块 Microsoft Teams 0.9.6 教程

我现在将切换回 ISE 并在这里执行相同的操作。

[玩转系统] 新的 PowerShell 模块 Microsoft Teams 0.9.6 教程

最后我们可以在这里做一些很酷的事情。

使用 MS Teams PowerShell

如果您使用“Get-Team”,组织中的所有团队都会显示在 shell 中。但您只能看到组 ID、显示名称和描述。没有那么多信息。因此,我创建了一个简短的脚本,用于处理所有团队、用户、所有者、访客,并在 GridView(单独的窗口)中显示结果,另请参阅评论!

$userid = "[email protected]"
$Creds = Get-Credential $userid
Connect-MicrosoftTeams -Credential $Creds
#generate array for custom object
$teamsinfo = @()
#get all teams from organisation
$teams = get-team 
#find members, owner, guest
foreach($team in $teams){
  $displayname = ($team.DisplayName)
  $Description = ($team.Description)
  $groupid = $team.groupid
  $members = (Get-TeamUser -GroupId $groupid -Role Member).User
  $owner = (Get-TeamUser -GroupId $groupid -Role Owner).User
  $guests = (Get-TeamUser -GroupId $groupid -Role Guest).User
   #custom object for output
  $teamsinfo += [pscustomobject]@{
    DisplayName   = $displayname
    Owner = ("$owner")
    Members = ("$members")
    Guests = ("$guests")
    Description = ("$Description")
  }
}
#show teaminformation in OutGrid-View
$teamsinfo | Sort-Object DisplayName | Out-GridView -Title "All Office365 Groups created in MS Teams" 

  • [玩转系统] 新的 PowerShell 模块 Microsoft Teams 0.9.6 教程

看起来很不错,但我认为将此信息作为 html 报告会更好。没那么复杂。

#show teaminfo in html site
$Header = @"
<style>
TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}
TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #6264A7;}
TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}
</style>
"@
$htmlreport = $teamsinfo | ConvertTo-Html -Head $Header 
$htmlreport | Out-File .\teams.html
Invoke-Item .\teams.html
  • [玩转系统] 新的 PowerShell 模块 Microsoft Teams 0.9.6 教程

还不错,通过邮件将该 html 报告发送给 MSTeam 管理员或类似的东西可能会很有用。那么让我们开始吧。在我的实验室中,我使用 O365 服务器进行中继,但您也可以使用本地邮件服务器。

注意:如果您在线使用 Exchange,“FROM”用户必须拥有 Exchange 邮箱(已颁发许可证)

$date = Get-Date
Send-MailMessage -From [email protected] -To "General - sharepoint-demo <[email protected]>" -cc [email protected] -Subject "MicrosoftTeamsReport $date" -BodyAsHtml "$htmlreport" -SmtpServer "smtp.office365.com"  -Credential $Creds -UseSsl -Port 587

这是对 发送邮件消息

也可以使用逗号分隔多个收件人。

我从哪里获得团队的电子邮件地址?打开 Teams 并选择您想要获取邮件地址的渠道。

  • [玩转系统] 新的 PowerShell 模块 Microsoft Teams 0.9.6 教程

  • [玩转系统] 新的 PowerShell 模块 Microsoft Teams 0.9.6 教程

之后,我们将脚本的每个部分合并在一起,这是完整的脚本:

$userid = "[email protected]"
$Creds = Get-Credential $userid
Connect-MicrosoftTeams -Credential $Creds
#generate array for custom object
$teamsinfo = @()
#get all teams from organisation
$teams = get-team 
#find members, owner, guest
foreach($team in $teams){
  $displayname = ($team.DisplayName)
  $Description = ($team.Description)
  $groupid = $team.groupid
  $members = (Get-TeamUser -GroupId $groupid -Role Member).User
  $owner = (Get-TeamUser -GroupId $groupid -Role Owner).User
  $guests = (Get-TeamUser -GroupId $groupid -Role Guest).User
   #custom object for output
  $teamsinfo += [pscustomobject]@{
    DisplayName   = $displayname
    Owner = ("$owner")
    Members = ("$members")
    Guests = ("$guests")
    Description = ("$Description")
  }
}
#show teaminformation in OutGrid-View
$teamsinfo | Sort-Object DisplayName | Out-GridView -Title "All Office365 Groups created in MS Teams" 
#show teaminfo in html site
$Header = @"
<style>
TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}
TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #6264A7;}
TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}
</style>
"@
$htmlreport = $teamsinfo | ConvertTo-Html -Head $Header 
$htmlreport | Out-File .\teams.html
Invoke-Item .\teams.html
$date = Get-Date
Send-MailMessage -From [email protected] -To "General - sharepoint-demo <[email protected]>" -cc [email protected] -Subject "MicrosoftTeamsReport $date" -BodyAsHtml "$htmlreport" -SmtpServer "smtp.office365.com"  -Credential $Creds -UseSsl -Port 587
  • [玩转系统] 新的 PowerShell 模块 Microsoft Teams 0.9.6 教程

当然,您还可以使用 PowerShell 执行其他一些出色的功能,但本教程将介绍如何获取一些信息。如果您喜欢这篇文章,请点击“有帮助”。感谢您阅读并查看我的其他文章。玩得开心。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯