Forum Discussion
PowerShell script for reading team information
Hi, Melina you can use the below Graph PowerShell script to read teams information to satisfy your needs.
$teams = Get-MgGroup -Filter "resourceProvisioningOptions/Any(x:x eq 'Team')"
foreach ($team in $teams){$teamName = $team.DisplayName
$teamId = $team.Id
Write-Host "Team Name: $teamName"
$GroupOwner = get-mggroupowner -GroupId $teamId| Select AdditionalProperties
$hashtable = $GroupOwner.AdditionalProperties
Write-Host "Team Owner: $($hashtable.displayName) `n"
$channels = Get-MgTeamChannel -TeamId $teamId
foreach ($channel in $channels) {$channelName = $channel.DisplayName
Write-Host "Channel Name: $channelName `n"
$members = Get-MgTeamChannelMember -TeamId $teamId -ChannelId $channel.Id
foreach ($member in $members) {
Write-Host "Member: $($member.DisplayName)"
}
$messages = Get-MgTeamChannelMessage -TeamId $TeamId -ChannelId $channel.Id
foreach ($message in $messages) {
foreach ($attachment in $message.Attachments) {
$fileName = $attachment.Name
$user = Get-MgUser -UserId $message.From.User.Id
Write-Host "File Name: $fileName"
Write-Host "Sent by: $($user.DisplayName) `n"
}
}
}Write-Host "`n`n"
}
Further more, to get additional information on creating new team, modifying teams, managing channels and more using Graph PowerShell, refer the following blog: https://m365scripts.com/microsoft-teams/top-10-cmdlets-to-manage-teams-using-microsoft-graph-powershell/
- MelinaJul 04, 2023Copper Contributor
Thiraviam5316thank you!
I am facing the next challenge:
Can you help me further, which role or settings are necessary besides Global Admin? And where these roles must be assigned?
- Thiraviam5316Jul 05, 2023Brass Contributor
Melina You must connect to the Microsoft Graph PowerShell with the required scopes for accessing the channel member: ChannelMember.Read.All, ChannelMember.ReadWrite.All
For eg,
Connect-MgGraph -Scopes "ChannelMember.Read.All, ChannelMember.ReadWrite.All"
After Connecting to the Graph PowerShell, you can run the script to get the Teams report.