I had to leave yesterday so stopped my previous post abruptly. In my previous post I had mentioned that after an account migration the user couldn’t see any of their teams so I changed their role from member/owner to owner/member and back, and that fixed the issue. However they couldn’t see any of the channels they previously had access to.
I prepared a report of all the channels in the teams the user is a member of via this snippet:
1 2 3 4 5 6 7 8 9 10 11 12 |
$outputObjArray = [System.Collections.ArrayList]@() $user = "abc@def.com" Get-Team -user $user | ForEach-Object { $OutputHash = [ordered]@{ "Team" = (Get-Team -GroupId $_.GroupId).DisplayName "GroupId" = $_.GroupId "Channels" = (Get-TeamChannel -GroupId $_.GroupId | Where-Object { $_.MembershipType -eq "Private" }).DisplayName -join '; ' } $outputObjArray.Add($OutputHash) | Out-Null } $outputObjArray | ForEach-Object{ [PSCustomobject]$_ } | Export-CSV -NoTypeInformation $reportFileName |
Sent the CSV to the user so they can select the ones they were a member of. The channels are in a single column with semi-colons separating them.
Armed with that output I ran the following to add the user back to the channels:
1 2 3 4 5 6 7 8 9 10 |
$user = "abc@def.com" Import-Csv $reportFileName | ForEach-Object { $channels = $_.Channels -split ';\s*' foreach ($channel in $channels) { if ($channel -ne "NONE" -and $channel.Length -ne 0) { "$($_.Team) | $channel" Add-TeamChannelUser -GroupId $_.GroupId -DisplayName $channel -User $user } } } |
The “NONE” and length 0 checks were necessary to ignore remarks from the user in the CSV file.
In this case I went with adding the user as a member, but I could have used the -Role Owner
switch to add as an owner.
I have more migrations to do, so I figured I should make a list of all teams a user is member of, find out the private channels, and if the user is in any of them then capture the info. Here’s what I came up with:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
$outputObjArray = [System.Collections.ArrayList]@() $user = "abc@def.com" $reportFileName = "./report.csv" Get-Team -user $user | ForEach-Object { Write-Host "Processing $($_.DisplayName)" # Capture the team name and Id $OutputHash = [ordered]@{ "Team" = (Get-Team -GroupId $_.GroupId).DisplayName "GroupId" = $_.GroupId "Private Channels" = "NONE" } # Get the private channels $privateChannels = Get-TeamChannel -GroupId $_.GroupId | Where-Object { $_.MembershipType -eq "Private" } # If the count isn't 0, process them if ($privateChannels.Count -ne 0) { $groupId = $_.GroupId $channels = @() # Create an array of all the channels where this user has a role $channels += @($privateChannels | ForEach-Object { $channelName = $_.DisplayName $role = "" $role = (Get-TeamChannelUser -GroupId $groupId -DisplayName $_.DisplayName | Where-Object { $_.User -eq $user }).Role if ($role.Length -ne 0) { "$channelName | $role" } else { "" } }) # Join this array into a string; skip any empty elements (coz there would be empty elements from the output above) $OutputHash."Private Channels" = $($channels | Where-Object { $_.length -ne 0 }) -join '; ' } $outputObjArray.Add($OutputHash) | Out-Null } $outputObjArray | ForEach-Object{ [PSCustomobject]$_ } | Export-CSV -NoTypeInformation $reportFileName |