我是 PowerShell 和 Teams 管理中心的新手,因此感谢您提供的任何帮助和反馈。
我正在尝试创建一个脚本,从 (1) Get-UnifiedGroup 收集 Teams 数据,然后从 (2) Get-Recipient 和 (3) Get-Teams 收集其他信息。从 (1) 和 (2) 收集信息的过程成功了。但是,要使用 MicrosoftTeams 模块(在 PowerShell 中),我需要群组编号, 不是全局唯一标识符或者交换GUID(Get-UnifiedGroup 获取)。为了获取所需的信息,我添加了 (2) 来获取拥有者(3)得到群组编号。[如果你知道更好的方法,我很乐意听取。]
我用[统一组].别名然后从 Get-Teams (Get-Team -MailNickName) 中查找信息[统一组].别名)[我正在使用[统一组].显示名称之前,但是存在已知错误,Get-Team 无法接受“&”。“解决方案”是使用“[System.Web.HttpUtility]::UrlEncode()”进行转换。但是,我不知道如何实施此解决方案,因此我改变了策略。]
我设法编写了一个比较成功的脚本。当我运行该脚本时,我成功地从 (1) Get-UnifiedGroup 和 (2) Get-Recipient 获取数据,但未能从 (3) Get-Teams 获取数据。如果有人能告诉我代码中的错误,我将不胜感激。
以下是整个代码(欢迎提出建议)。
Connect-ExchangeOnline -UserPrincipalName [my email]
#Connect-SPOService -Url https://[notcontoso]-admin.sharepoint.com/ [not needed in this script]
Connect-MicrosoftTeams
$Date = Get-Date -format "yyyyMMdd_HHmm"
$exportLocation = "D:\...\2. Reports\Get_AllTeamDetails_$Date.csv"
$Path=$exportLocation
#Main Command - Properties
$Properties = 'DisplayName', 'ManagedBy', 'Emailaddresses', 'Notes', 'AccessType', 'IsMembershipDynamic', 'GroupMemberCount', 'GroupExternalMemberCount', 'WhenCreated', 'WhenChanged', 'ExpirationTime', 'Guid', 'Alias', 'SharePointSiteUrl', 'SharePointDocumentsUrl', 'Language', 'ExchangeGuid'
#Main Command
$AllGroups = Get-UnifiedGroup -Filter {ResourceProvisioningOptions -eq "Team"} -ResultSize Unlimited | Select $Properties
$Result = @()
$i = 1
$TotalGroups = $AllGroups.Count
#Secondary Command to get Owners
Foreach($Group in $AllGroups)
{
$MailsOwners = @()
$TeamsDetails = @()
Foreach($Owner in $Group.ManagedBy)
{
Write-Progress -Activity "Processing $($Group.DisplayName)" -Status "$i out of $TotalGroups completed"
$MailOwner = $null
$MailOwner = Get-Recipient $Owner | select PrimarySMTPAddress
$MailsOwners += $MailOwner.PrimarySMTPAddress
}
$MailsOwners = $MailsOwners -join ";"
##Write-Host "MailOwners complete"
#Tertiary Command to...
Foreach($Team in $Group.DisplayName)
{
Write-Progress -Activity "Processing $($Group.DisplayName)" -Status "$i out of $TotalGroups completed"
$TeamDetail = $null
$TeamDetail = Get-Team -DisplayName $Team
$TeamsDetails += $TeamDetail
}
$TeamsDetails = $TeamsDetails -join ";"
##Write-Host "TeamDetails complete"
$i++
$Props = $null
$Props = [ordered]@{
GroupDisplayName = $Group.DisplayName
MailNickName = $TeamsDetails.MailNickName
Description = $TeamsDetails.Description
ManagedBy = $Group.ManagedBy
GroupOwnersMails = $MailsOwners
Emails = $Group.Emailaddresses
Alias = $Group.Alias
Notes = $Group.Notes
Members = $Group.GroupMemberCount
ExternalMembers = $Group.GroupExternalMemberCount
GroupID = $TeamsDetails.GroupID
InternalID = $TeamsDetails.InternalID
GUID = $Group.GUID
ExchangeGUID = $Group.ExchangeGUID
Created = $Group.WhenCreated
Changed = $Group.WhenChanged
Expiration = $Group.ExpirationTime
SPSiteURL = $Group.SharePointSiteUrl
SPDocumentsURL = $Group.SharePointDocumentsUrl
AccessType = $Group.AccessType
Visibility = $TeamsDetails.Visibility
Archived = $TeamsDetails.Archived
Language = $Group.Language
IsMEMdynamic = $Group.IsMembershipDynamic
}
$Outputtmp = New-Object PSObject -Property $Props
$Result += $Outputtmp
}
$Result | Export-Csv -Path $Path -NoTypeInformation -Encoding UTF8
Write-Host "Report exported to $($Path)"