Forum Discussion
Powershell command to export ALL private Teams memberships, including private Channel memberships
There is currently a major issue that Microsoft is not saying is a bug. When a user is soft-deleted (what happens when we disconnect that user from the on-premise AD to force the cloud-only conversion) they are soft-deleted in O365. The restore works great, however, Teams does not work afterwards..
When the account is restored, all the licenses are retained, all the email, security, private teams memberships are also restored, however, the private channel memberships are permanently removed and cannot be recovered. The only way to get the access back is to go into Teams Admin Centre, open each Team/Channel combo and re-add the user.
What happens if you don't actually know what private channel they are members of and what that membership is (member/owner)? You're SOL.
I've tried many powershell scripts but they won't show me ALL private teams with all private channel memberships for all teams/channels/users. I would nave to run it for each team/channel name combo and we have many.
Anyone have a good script to use?
- I have one that works perfectly that Microsoft gave to me.
First install and connect:
Install-Module PowerShellGet -RequiredVersion 2.2.4.1
Install-Module -Name MicrosoftTeams -RequiredVersion 3.0.0
Connect-MicrosoftTeams
Then:
1. Copy the ps1 file to your downloads folder
2. cd C:\Users\username\Downloads
3. .\TeamsChannelMemberReport.ps1
Choose option 2 to export all and it will export to downloads.
Save this as TeamsChannelMemberReport.ps1:
<#
.Requires -version 2 - Connect-MicrosoftTeams and then Run the script in Powershell
Updated on 28 Feb 2021
.SYNOPSIS
.\TeamsChannelMemberReport.ps1 - It Can Display all the Teams and its Channels and its members on a List
Or It can Export to a CSV file
With Export of Specific teams
Example 1
PS C:\Scripts> .\TeamsChannelMemberReportv1.0.ps1
Teams Channel Member Report
----------------------------
1.Display in Microsoft Teams Shell
2.Export to CSV File
3.Display Specific Microsoft Team in Shell
4.Export Specific Microsoft Team to CSV File
Choose The Task: 1
User SMTP Address Role Channel DisplayName Team DisplayName
----------------- ---- ------------------- ----------------
Email address removed Owner General Teams_Azure365pro
Email address removed Member General Teams_Azure365pro
Email address removed Member General Teams_Azure365pro
Email address removed Owner General Teams_Azure365pro
Email address removed Member General Teams_Azure365pro
Email address removed Member General Teams_Azure365pro
Email address removed Owner General InformationTec...
Email address removed Member General InformationTec...
Email address removed Owner ServiceDesk Team InformationTec...
Email address removed Owner Infrastructure Team InformationTec...
Example 2
PS C:\Scripts> .\TeamsChannelMemberReportv1.0.ps1
Teams Channel Member Report
----------------------------
1.Display in Microsoft Teams Shell
2.Export to CSV File
3.Display Specific Microsoft Team in Shell
4.Export Specific Microsoft Team to CSV File
Choose The Task: 2
Enter the Path of CSV file (Eg. C:\Teams.csv): c:\teams.csv
.Author
Written By: Satheshwaran Manoharan
Change Log
V1.0, 13/05/2020 - Initial version
#>
Write-host "
Teams Channel Member Report
----------------------------
1.Display in Microsoft Teams Shell
2.Export to CSV File
3.Display Specific Microsoft Team in Shell
4.Export Specific Microsoft Team to CSV File"-ForeGround "Cyan"
#----------------
# Script
#----------------
Write-Host " "
$number = Read-Host "Choose The Task"
$output = @()
switch ($number)
{
1 {
$i = 0
$AllTeams = Get-Team
Foreach ($Team in $AllTeams)
{
$AllChannels = Get-TeamChannel -GroupID $Team.GroupID
Foreach ($Channel in $AllChannels)
{
$AllMembers = Get-TeamChannelUser -GroupId $Team.GroupID -DisplayName $channel.DisplayName
Foreach ($member in $AllMembers)
{
$userObj = New-Object PSObject
$userObj | Add-Member NoteProperty -Name "User SMTP Address" -Value $member.User
$userObj | Add-Member NoteProperty -Name "Role" -Value $member.role
$userObj | Add-Member NoteProperty -Name "Channel DisplayName" -Value $Channel.DisplayName
$userObj | Add-Member NoteProperty -Name "Team DisplayName" -Value $Team.DisplayName
$output += $UserObj
}
}
# update counters and write progress
$i++
Write-Progress -activity "Scanning Teams . . .Channels . . . Members" -status "Scanned: $i of $($AllTeams.Count)" -percentComplete (($i / $AllTeams.Count) * 100)
Write-Output $Output
}
;Break}
2 {
$i = 0
$CSVfile = Read-Host "Enter the Path of CSV file (Eg. C:\Teams.csv)"
$AllTeams = Get-Team
Foreach ($Team in $AllTeams)
{
$AllChannels = Get-TeamChannel -GroupID $Team.GroupID
Foreach ($Channel in $AllChannels)
{
$AllMembers = Get-TeamChannelUser -GroupId $Team.GroupID -DisplayName $channel.DisplayName
Foreach ($member in $AllMembers)
{
$userObj = New-Object PSObject
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $member.Name
$userObj | Add-Member NoteProperty -Name "UserId" -Value $member.UserId
$userObj | Add-Member NoteProperty -Name "User SMTP Address" -Value $member.User
$userObj | Add-Member NoteProperty -Name "Role" -Value $member.role
$userObj | Add-Member NoteProperty -Name "Channel DisplayName" -Value $Channel.DisplayName
$userObj | Add-Member NoteProperty -Name "Channel Description" -Value $Channel.Description
$userObj | Add-Member NoteProperty -Name "Channel MembershipType" -Value $Channel.MembershipType
$userObj | Add-Member NoteProperty -Name "Team GroupID" -Value $Team.GroupId
$userObj | Add-Member NoteProperty -Name "Team DisplayName" -Value $Team.DisplayName
$userObj | Add-Member NoteProperty -Name "Team Description" -Value $Team.Description
$userObj | Add-Member NoteProperty -Name "Team Visibility" -Value $Team.Visibility
$userObj | Add-Member NoteProperty -Name "Team MailNickName" -Value $Team.MailNickName
$userObj | Add-Member NoteProperty -Name "Team Classification" -Value $Team.Classification
$userObj | Add-Member NoteProperty -Name "Team Archived" -Value $Team.Archived
$userObj | Add-Member NoteProperty -Name "Team AllowGiphy" -Value $Team.AllowGiphy
$userObj | Add-Member NoteProperty -Name "Team GiphyContentRating" -Value $Team.GiphyContentRating
$userObj | Add-Member NoteProperty -Name "Team AllowStickersAndMemes" -Value $Team.AllowStickersAndMemes
$userObj | Add-Member NoteProperty -Name "Team AllowGuestCreateUpdateChannels" -Value $Team.AllowGuestCreateUpdateChannels
$userObj | Add-Member NoteProperty -Name "Team AllowGuestDeleteChannels" -Value $Team.AllowGuestDeleteChannels
$userObj | Add-Member NoteProperty -Name "Team AllowCreateUpdateChannels" -Value $Team.AllowCreateUpdateChannels
$userObj | Add-Member NoteProperty -Name "Team AllowCreatePrivateChannels" -Value $Team.AllowCreatePrivateChannels
$userObj | Add-Member NoteProperty -Name "Team AllowDeleteChannels" -Value $Team.AllowDeleteChannels
$userObj | Add-Member NoteProperty -Name "Team AllowAddRemoveApps" -Value $Team.AllowAddRemoveApps
$userObj | Add-Member NoteProperty -Name "Team AllowCreateUpdateRemoveTabs" -Value $Team.AllowCreateUpdateRemoveTabs
$userObj | Add-Member NoteProperty -Name "Team AllowCreateUpdateRemoveConnectors" -Value $Team.AllowCreateUpdateRemoveConnectors
$userObj | Add-Member NoteProperty -Name "Team AllowUserEditMessages" -Value $Team.AllowUserEditMessages
$userObj | Add-Member NoteProperty -Name "Team AllowUserDeleteMessages " -Value $Team.AllowUserDeleteMessages
$userObj | Add-Member NoteProperty -Name "Team AllowOwnerDeleteMessages" -Value $Team.AllowOwnerDeleteMessages
$userObj | Add-Member NoteProperty -Name "Team AllowTeamMentions" -Value $Team.AllowTeamMentions
$userObj | Add-Member NoteProperty -Name "Team AllowChannelMentions" -Value $Team.AllowChannelMentions
$userObj | Add-Member NoteProperty -Name "Team ShowInTeamsSearchAndSuggestions" -Value $Team.ShowInTeamsSearchAndSuggestions
$output += $UserObj
}
}
# update counters and write progress
$i++
Write-Progress -activity "Scanning Teams . . .Channels . . . Members" -status "Scanned: $i of $($AllTeams.Count)" -percentComplete (($i / $AllTeams.Count) * 100)
$output | Export-csv -Path $CSVfile -NoTypeInformation -Encoding UTF8
}
;Break}
3 {
$i = 0
$Teamname = Read-Host "Enter the Team Display name or Range (Eg. Teamname , Team*,*Team)"
$AllTeams = Get-Team | Where-object {$_.DisplayName -like $Teamname}
Foreach ($Team in $AllTeams)
{
$AllChannels = Get-TeamChannel -GroupID $Team.GroupID
Foreach ($Channel in $AllChannels)
{
$AllMembers = Get-TeamChannelUser -GroupId $Team.GroupID -DisplayName $channel.DisplayName
Foreach ($member in $AllMembers)
{
$userObj = New-Object PSObject
$userObj | Add-Member NoteProperty -Name "User SMTP Address" -Value $member.User
$userObj | Add-Member NoteProperty -Name "Role" -Value $member.role
$userObj | Add-Member NoteProperty -Name "Channel DisplayName" -Value $Channel.DisplayName
$userObj | Add-Member NoteProperty -Name "Team DisplayName" -Value $Team.DisplayName
$output += $UserObj
}
}
# update counters and write progress
$i++
Write-Progress -activity "Scanning Teams . . .Channels . . . Members" -status "Scanned: $i of $($AllTeams.Count)" -percentComplete (($i / $AllTeams.Count) * 100)
Write-Output $Output
}
;Break}
4 {
$i = 0
$CSVfile = Read-Host "Enter the Path of CSV file (Eg. C:\Teams.csv)"
$Teamname = Read-Host "Enter the Team Display name or Range (Eg. Teamname , Team*,*Team)"
$AllTeams = Get-Team | Where-object {$_.DisplayName -like $Teamname}
Foreach ($Team in $AllTeams)
{
$AllChannels = Get-TeamChannel -GroupID $Team.GroupID
Foreach ($Channel in $AllChannels)
{
$AllMembers = Get-TeamChannelUser -GroupId $Team.GroupID -DisplayName $channel.DisplayName
Foreach ($member in $AllMembers)
{
$userObj = New-Object PSObject
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $member.Name
$userObj | Add-Member NoteProperty -Name "UserId" -Value $member.UserId
$userObj | Add-Member NoteProperty -Name "User SMTP Address" -Value $member.User
$userObj | Add-Member NoteProperty -Name "Role" -Value $member.role
$userObj | Add-Member NoteProperty -Name "Channel DisplayName" -Value $Channel.DisplayName
$userObj | Add-Member NoteProperty -Name "Channel Description" -Value $Channel.Description
$userObj | Add-Member NoteProperty -Name "Channel MembershipType" -Value $Channel.MembershipType
$userObj | Add-Member NoteProperty -Name "Team GroupID" -Value $Team.GroupId
$userObj | Add-Member NoteProperty -Name "Team DisplayName" -Value $Team.DisplayName
$userObj | Add-Member NoteProperty -Name "Team Description" -Value $Team.Description
$userObj | Add-Member NoteProperty -Name "Team Visibility" -Value $Team.Visibility
$userObj | Add-Member NoteProperty -Name "Team MailNickName" -Value $Team.MailNickName
$userObj | Add-Member NoteProperty -Name "Team Classification" -Value $Team.Classification
$userObj | Add-Member NoteProperty -Name "Team Archived" -Value $Team.Archived
$userObj | Add-Member NoteProperty -Name "Team AllowGiphy" -Value $Team.AllowGiphy
$userObj | Add-Member NoteProperty -Name "Team GiphyContentRating" -Value $Team.GiphyContentRating
$userObj | Add-Member NoteProperty -Name "Team AllowStickersAndMemes" -Value $Team.AllowStickersAndMemes
$userObj | Add-Member NoteProperty -Name "Team AllowGuestCreateUpdateChannels" -Value $Team.AllowGuestCreateUpdateChannels
$userObj | Add-Member NoteProperty -Name "Team AllowGuestDeleteChannels" -Value $Team.AllowGuestDeleteChannels
$userObj | Add-Member NoteProperty -Name "Team AllowCreateUpdateChannels" -Value $Team.AllowCreateUpdateChannels
$userObj | Add-Member NoteProperty -Name "Team AllowCreatePrivateChannels" -Value $Team.AllowCreatePrivateChannels
$userObj | Add-Member NoteProperty -Name "Team AllowDeleteChannels" -Value $Team.AllowDeleteChannels
$userObj | Add-Member NoteProperty -Name "Team AllowAddRemoveApps" -Value $Team.AllowAddRemoveApps
$userObj | Add-Member NoteProperty -Name "Team AllowCreateUpdateRemoveTabs" -Value $Team.AllowCreateUpdateRemoveTabs
$userObj | Add-Member NoteProperty -Name "Team AllowCreateUpdateRemoveConnectors" -Value $Team.AllowCreateUpdateRemoveConnectors
$userObj | Add-Member NoteProperty -Name "Team AllowUserEditMessages" -Value $Team.AllowUserEditMessages
$userObj | Add-Member NoteProperty -Name "Team AllowUserDeleteMessages " -Value $Team.AllowUserDeleteMessages
$userObj | Add-Member NoteProperty -Name "Team AllowOwnerDeleteMessages" -Value $Team.AllowOwnerDeleteMessages
$userObj | Add-Member NoteProperty -Name "Team AllowTeamMentions" -Value $Team.AllowTeamMentions
$userObj | Add-Member NoteProperty -Name "Team AllowChannelMentions" -Value $Team.AllowChannelMentions
$userObj | Add-Member NoteProperty -Name "Team ShowInTeamsSearchAndSuggestions" -Value $Team.ShowInTeamsSearchAndSuggestions
$output += $UserObj
}
}
# update counters and write progress
$i++
Write-Progress -activity "Scanning Teams . . .Channels . . . Members" -status "Scanned: $i of $($AllTeams.Count)" -percentComplete (($i / $AllTeams.Count) * 100)
$output | Export-csv -Path $CSVfile -NoTypeInformation -Encoding UTF8
}
;Break}
Default {Write-Host "No matches found , Enter Options 1 or 2" -ForeGround "red"}
}
- Therese_SolimenoModerator
Hi luvsql Let's ask some of our super-user MVPs: ChristianJBergstrom adam deltinger ChrisHoardMVP LinusCansby StevenC365 ChrisWebbTech
- This looks interesting, however it would need to be tested
https://github.com/admindroid-community/powershell-scripts/blob/master/Microsoft%20Teams-Private%20Channel%20Management/PrivateChannelManagement.ps1
Particularly this section:
9{
$Result=""
$Results=@()
Write-Host Exporting all Private Channel"'s" Members and Owners report...
$Count=0
$Path="./AllPrivateChannels Members and Owners Report_$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv"
Get-Team | foreach {
$TeamName=$_.DisplayName
$GroupId=$_.GroupId
$PrivateChannels=(Get-TeamChannel -GroupId $GroupId -MembershipType Private).DisplayName
foreach($PrivateChannel in $PrivateChannels)
{
Write-Progress -Activity "`n Processed Private Channel count: $Count "`n" Currently Processing: $PrivateChannel"
$Count++
Get-TeamChannelUser -GroupId $GroupId -DisplayName $PrivateChannel | foreach {
$Name=$_.Name
$UPN=$_.User
$Role=$_.Role
$Result=@{'Teams Name'=$TeamName;'Private Channel Name'=$PrivateChannel;'UPN'=$UPN;'User Display Name'=$Name;'Role'=$Role}
$Results= New-Object psobject -Property $Result
$Results | select 'Teams Name','Private Channel Name',UPN,'User Display Name',Role | Export-Csv $Path -NoTypeInformation -Append
}- luvsqlSteel ContributorI have one that works perfectly that Microsoft gave to me.
First install and connect:
Install-Module PowerShellGet -RequiredVersion 2.2.4.1
Install-Module -Name MicrosoftTeams -RequiredVersion 3.0.0
Connect-MicrosoftTeams
Then:
1. Copy the ps1 file to your downloads folder
2. cd C:\Users\username\Downloads
3. .\TeamsChannelMemberReport.ps1
Choose option 2 to export all and it will export to downloads.
Save this as TeamsChannelMemberReport.ps1:
<#
.Requires -version 2 - Connect-MicrosoftTeams and then Run the script in Powershell
Updated on 28 Feb 2021
.SYNOPSIS
.\TeamsChannelMemberReport.ps1 - It Can Display all the Teams and its Channels and its members on a List
Or It can Export to a CSV file
With Export of Specific teams
Example 1
PS C:\Scripts> .\TeamsChannelMemberReportv1.0.ps1
Teams Channel Member Report
----------------------------
1.Display in Microsoft Teams Shell
2.Export to CSV File
3.Display Specific Microsoft Team in Shell
4.Export Specific Microsoft Team to CSV File
Choose The Task: 1
User SMTP Address Role Channel DisplayName Team DisplayName
----------------- ---- ------------------- ----------------
Email address removed Owner General Teams_Azure365pro
Email address removed Member General Teams_Azure365pro
Email address removed Member General Teams_Azure365pro
Email address removed Owner General Teams_Azure365pro
Email address removed Member General Teams_Azure365pro
Email address removed Member General Teams_Azure365pro
Email address removed Owner General InformationTec...
Email address removed Member General InformationTec...
Email address removed Owner ServiceDesk Team InformationTec...
Email address removed Owner Infrastructure Team InformationTec...
Example 2
PS C:\Scripts> .\TeamsChannelMemberReportv1.0.ps1
Teams Channel Member Report
----------------------------
1.Display in Microsoft Teams Shell
2.Export to CSV File
3.Display Specific Microsoft Team in Shell
4.Export Specific Microsoft Team to CSV File
Choose The Task: 2
Enter the Path of CSV file (Eg. C:\Teams.csv): c:\teams.csv
.Author
Written By: Satheshwaran Manoharan
Change Log
V1.0, 13/05/2020 - Initial version
#>
Write-host "
Teams Channel Member Report
----------------------------
1.Display in Microsoft Teams Shell
2.Export to CSV File
3.Display Specific Microsoft Team in Shell
4.Export Specific Microsoft Team to CSV File"-ForeGround "Cyan"
#----------------
# Script
#----------------
Write-Host " "
$number = Read-Host "Choose The Task"
$output = @()
switch ($number)
{
1 {
$i = 0
$AllTeams = Get-Team
Foreach ($Team in $AllTeams)
{
$AllChannels = Get-TeamChannel -GroupID $Team.GroupID
Foreach ($Channel in $AllChannels)
{
$AllMembers = Get-TeamChannelUser -GroupId $Team.GroupID -DisplayName $channel.DisplayName
Foreach ($member in $AllMembers)
{
$userObj = New-Object PSObject
$userObj | Add-Member NoteProperty -Name "User SMTP Address" -Value $member.User
$userObj | Add-Member NoteProperty -Name "Role" -Value $member.role
$userObj | Add-Member NoteProperty -Name "Channel DisplayName" -Value $Channel.DisplayName
$userObj | Add-Member NoteProperty -Name "Team DisplayName" -Value $Team.DisplayName
$output += $UserObj
}
}
# update counters and write progress
$i++
Write-Progress -activity "Scanning Teams . . .Channels . . . Members" -status "Scanned: $i of $($AllTeams.Count)" -percentComplete (($i / $AllTeams.Count) * 100)
Write-Output $Output
}
;Break}
2 {
$i = 0
$CSVfile = Read-Host "Enter the Path of CSV file (Eg. C:\Teams.csv)"
$AllTeams = Get-Team
Foreach ($Team in $AllTeams)
{
$AllChannels = Get-TeamChannel -GroupID $Team.GroupID
Foreach ($Channel in $AllChannels)
{
$AllMembers = Get-TeamChannelUser -GroupId $Team.GroupID -DisplayName $channel.DisplayName
Foreach ($member in $AllMembers)
{
$userObj = New-Object PSObject
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $member.Name
$userObj | Add-Member NoteProperty -Name "UserId" -Value $member.UserId
$userObj | Add-Member NoteProperty -Name "User SMTP Address" -Value $member.User
$userObj | Add-Member NoteProperty -Name "Role" -Value $member.role
$userObj | Add-Member NoteProperty -Name "Channel DisplayName" -Value $Channel.DisplayName
$userObj | Add-Member NoteProperty -Name "Channel Description" -Value $Channel.Description
$userObj | Add-Member NoteProperty -Name "Channel MembershipType" -Value $Channel.MembershipType
$userObj | Add-Member NoteProperty -Name "Team GroupID" -Value $Team.GroupId
$userObj | Add-Member NoteProperty -Name "Team DisplayName" -Value $Team.DisplayName
$userObj | Add-Member NoteProperty -Name "Team Description" -Value $Team.Description
$userObj | Add-Member NoteProperty -Name "Team Visibility" -Value $Team.Visibility
$userObj | Add-Member NoteProperty -Name "Team MailNickName" -Value $Team.MailNickName
$userObj | Add-Member NoteProperty -Name "Team Classification" -Value $Team.Classification
$userObj | Add-Member NoteProperty -Name "Team Archived" -Value $Team.Archived
$userObj | Add-Member NoteProperty -Name "Team AllowGiphy" -Value $Team.AllowGiphy
$userObj | Add-Member NoteProperty -Name "Team GiphyContentRating" -Value $Team.GiphyContentRating
$userObj | Add-Member NoteProperty -Name "Team AllowStickersAndMemes" -Value $Team.AllowStickersAndMemes
$userObj | Add-Member NoteProperty -Name "Team AllowGuestCreateUpdateChannels" -Value $Team.AllowGuestCreateUpdateChannels
$userObj | Add-Member NoteProperty -Name "Team AllowGuestDeleteChannels" -Value $Team.AllowGuestDeleteChannels
$userObj | Add-Member NoteProperty -Name "Team AllowCreateUpdateChannels" -Value $Team.AllowCreateUpdateChannels
$userObj | Add-Member NoteProperty -Name "Team AllowCreatePrivateChannels" -Value $Team.AllowCreatePrivateChannels
$userObj | Add-Member NoteProperty -Name "Team AllowDeleteChannels" -Value $Team.AllowDeleteChannels
$userObj | Add-Member NoteProperty -Name "Team AllowAddRemoveApps" -Value $Team.AllowAddRemoveApps
$userObj | Add-Member NoteProperty -Name "Team AllowCreateUpdateRemoveTabs" -Value $Team.AllowCreateUpdateRemoveTabs
$userObj | Add-Member NoteProperty -Name "Team AllowCreateUpdateRemoveConnectors" -Value $Team.AllowCreateUpdateRemoveConnectors
$userObj | Add-Member NoteProperty -Name "Team AllowUserEditMessages" -Value $Team.AllowUserEditMessages
$userObj | Add-Member NoteProperty -Name "Team AllowUserDeleteMessages " -Value $Team.AllowUserDeleteMessages
$userObj | Add-Member NoteProperty -Name "Team AllowOwnerDeleteMessages" -Value $Team.AllowOwnerDeleteMessages
$userObj | Add-Member NoteProperty -Name "Team AllowTeamMentions" -Value $Team.AllowTeamMentions
$userObj | Add-Member NoteProperty -Name "Team AllowChannelMentions" -Value $Team.AllowChannelMentions
$userObj | Add-Member NoteProperty -Name "Team ShowInTeamsSearchAndSuggestions" -Value $Team.ShowInTeamsSearchAndSuggestions
$output += $UserObj
}
}
# update counters and write progress
$i++
Write-Progress -activity "Scanning Teams . . .Channels . . . Members" -status "Scanned: $i of $($AllTeams.Count)" -percentComplete (($i / $AllTeams.Count) * 100)
$output | Export-csv -Path $CSVfile -NoTypeInformation -Encoding UTF8
}
;Break}
3 {
$i = 0
$Teamname = Read-Host "Enter the Team Display name or Range (Eg. Teamname , Team*,*Team)"
$AllTeams = Get-Team | Where-object {$_.DisplayName -like $Teamname}
Foreach ($Team in $AllTeams)
{
$AllChannels = Get-TeamChannel -GroupID $Team.GroupID
Foreach ($Channel in $AllChannels)
{
$AllMembers = Get-TeamChannelUser -GroupId $Team.GroupID -DisplayName $channel.DisplayName
Foreach ($member in $AllMembers)
{
$userObj = New-Object PSObject
$userObj | Add-Member NoteProperty -Name "User SMTP Address" -Value $member.User
$userObj | Add-Member NoteProperty -Name "Role" -Value $member.role
$userObj | Add-Member NoteProperty -Name "Channel DisplayName" -Value $Channel.DisplayName
$userObj | Add-Member NoteProperty -Name "Team DisplayName" -Value $Team.DisplayName
$output += $UserObj
}
}
# update counters and write progress
$i++
Write-Progress -activity "Scanning Teams . . .Channels . . . Members" -status "Scanned: $i of $($AllTeams.Count)" -percentComplete (($i / $AllTeams.Count) * 100)
Write-Output $Output
}
;Break}
4 {
$i = 0
$CSVfile = Read-Host "Enter the Path of CSV file (Eg. C:\Teams.csv)"
$Teamname = Read-Host "Enter the Team Display name or Range (Eg. Teamname , Team*,*Team)"
$AllTeams = Get-Team | Where-object {$_.DisplayName -like $Teamname}
Foreach ($Team in $AllTeams)
{
$AllChannels = Get-TeamChannel -GroupID $Team.GroupID
Foreach ($Channel in $AllChannels)
{
$AllMembers = Get-TeamChannelUser -GroupId $Team.GroupID -DisplayName $channel.DisplayName
Foreach ($member in $AllMembers)
{
$userObj = New-Object PSObject
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $member.Name
$userObj | Add-Member NoteProperty -Name "UserId" -Value $member.UserId
$userObj | Add-Member NoteProperty -Name "User SMTP Address" -Value $member.User
$userObj | Add-Member NoteProperty -Name "Role" -Value $member.role
$userObj | Add-Member NoteProperty -Name "Channel DisplayName" -Value $Channel.DisplayName
$userObj | Add-Member NoteProperty -Name "Channel Description" -Value $Channel.Description
$userObj | Add-Member NoteProperty -Name "Channel MembershipType" -Value $Channel.MembershipType
$userObj | Add-Member NoteProperty -Name "Team GroupID" -Value $Team.GroupId
$userObj | Add-Member NoteProperty -Name "Team DisplayName" -Value $Team.DisplayName
$userObj | Add-Member NoteProperty -Name "Team Description" -Value $Team.Description
$userObj | Add-Member NoteProperty -Name "Team Visibility" -Value $Team.Visibility
$userObj | Add-Member NoteProperty -Name "Team MailNickName" -Value $Team.MailNickName
$userObj | Add-Member NoteProperty -Name "Team Classification" -Value $Team.Classification
$userObj | Add-Member NoteProperty -Name "Team Archived" -Value $Team.Archived
$userObj | Add-Member NoteProperty -Name "Team AllowGiphy" -Value $Team.AllowGiphy
$userObj | Add-Member NoteProperty -Name "Team GiphyContentRating" -Value $Team.GiphyContentRating
$userObj | Add-Member NoteProperty -Name "Team AllowStickersAndMemes" -Value $Team.AllowStickersAndMemes
$userObj | Add-Member NoteProperty -Name "Team AllowGuestCreateUpdateChannels" -Value $Team.AllowGuestCreateUpdateChannels
$userObj | Add-Member NoteProperty -Name "Team AllowGuestDeleteChannels" -Value $Team.AllowGuestDeleteChannels
$userObj | Add-Member NoteProperty -Name "Team AllowCreateUpdateChannels" -Value $Team.AllowCreateUpdateChannels
$userObj | Add-Member NoteProperty -Name "Team AllowCreatePrivateChannels" -Value $Team.AllowCreatePrivateChannels
$userObj | Add-Member NoteProperty -Name "Team AllowDeleteChannels" -Value $Team.AllowDeleteChannels
$userObj | Add-Member NoteProperty -Name "Team AllowAddRemoveApps" -Value $Team.AllowAddRemoveApps
$userObj | Add-Member NoteProperty -Name "Team AllowCreateUpdateRemoveTabs" -Value $Team.AllowCreateUpdateRemoveTabs
$userObj | Add-Member NoteProperty -Name "Team AllowCreateUpdateRemoveConnectors" -Value $Team.AllowCreateUpdateRemoveConnectors
$userObj | Add-Member NoteProperty -Name "Team AllowUserEditMessages" -Value $Team.AllowUserEditMessages
$userObj | Add-Member NoteProperty -Name "Team AllowUserDeleteMessages " -Value $Team.AllowUserDeleteMessages
$userObj | Add-Member NoteProperty -Name "Team AllowOwnerDeleteMessages" -Value $Team.AllowOwnerDeleteMessages
$userObj | Add-Member NoteProperty -Name "Team AllowTeamMentions" -Value $Team.AllowTeamMentions
$userObj | Add-Member NoteProperty -Name "Team AllowChannelMentions" -Value $Team.AllowChannelMentions
$userObj | Add-Member NoteProperty -Name "Team ShowInTeamsSearchAndSuggestions" -Value $Team.ShowInTeamsSearchAndSuggestions
$output += $UserObj
}
}
# update counters and write progress
$i++
Write-Progress -activity "Scanning Teams . . .Channels . . . Members" -status "Scanned: $i of $($AllTeams.Count)" -percentComplete (($i / $AllTeams.Count) * 100)
$output | Export-csv -Path $CSVfile -NoTypeInformation -Encoding UTF8
}
;Break}
Default {Write-Host "No matches found , Enter Options 1 or 2" -ForeGround "red"}
}
- luvsqlSteel Contributor
I was able to get a manager to speak to me about this issue. They have acknowledged the issue but are now saying it's supposed to happen and why I can't "just add their memberships back" as if that's such an easy endeavor. When I asked him how an admin is supposed to know every single Team (private) and Team Channels (private) and all their memberships and membership types, he actually suggested to me as solution: Create a spreadsheet and manually keep track of all the memberships. I'm not sure how I would even be able to do this since I have no clue when new channels are created, or new members added, so I guess he thinks I would have to look through every single one manually in the Teams Admin Centre.
This is Microsoft support in 2021. Keep a manual list because you'll lose your data.- luvsqlSteel ContributorI'm not giving up on this issue as it's too important to our users to lose all of their channel memberships. I spoke with a Team Lead for O365 Management and this person told me I should "ask the user what memberships they had" so that I could manually add them back. When you have 20-50+ Teams/Channels depending on the user, they are supposed to have everything listed somewhere to give me so I can manually add them back? I can't even get anyone from Microsoft to give money to to PAY for better support.