MicrosoftTeams PowerShell module
PowerShell scripts for Microsoft Teams stuff.
Get all owners of all teams and team channels
1## Documentation: https://learn.microsoft.com/en-us/powershell/module/teams/?view=teams-ps
2
3# Run the following command to install the latest PowerShellGet:
4Install-Module -Name PowerShellGet -Force -AllowClobber
5
6# Install the Teams PowerShell Module.
7Install-Module -Name MicrosoftTeams -Force -AllowClobber
8
9# To start working with Microsoft Teams PowerShell module, sign in with your Azure credentials.
10Connect-MicrosoftTeams
11
12$user =Read-Host -Prompt 'Input the user name'
13$teams = Get-Team -User $user
14$teamMemberships=@()
15$teamChannels=@()
16$teamChannelMemberships=@()
17
18$i = 1
19
20$teamMemberships = foreach ($team in $teams) {
21 $GroupId = $team.GroupId
22
23 Get-TeamUser -GroupId $GroupId | Select-Object *,@{Name="GroupId";Expression={$GroupId}}
24 $channels = Get-TeamAllChannel -GroupId $GroupId | Select-Object *,@{Name="GroupId";Expression={$GroupId}}
25 $teamChannels += $channels
26
27 $teamChannelMemberships += foreach ($channel in $channels) {
28 $channelDisplayName = $channel.DisplayName
29 Get-TeamChannelUser -GroupId $GroupId -DisplayName $channelDisplayName | Select-Object *,@{Name="GroupId";Expression={$GroupId}}
30 }
31
32 $percent = [Math]::Round((100 * $i) / $teams.Length)
33 Write-Progress -Activity "Search in Progress" -Status "$percent% complete"
34 $i++
35 }
36
37$teams | Export-Csv -Path "teams.csv" -NoTypeInformation
38$teamMemberships | Export-Csv -Path "team-memberships.csv" -NoTypeInformation
39$teamChannels | Export-Csv -Path "team-channels.csv" -NoTypeInformation
40$teamChannelMemberShips | Export-Csv -Path "team-channel-memberships.csv" -NoTypeInformation