Restoring private channel owners in EDU teams

Brass Contributor

Hi there,

 

Not a question... just something I would like to share...

 

The Atlas College is a school in The Netherlands. 5 Schools under one board... 500+ staf and 4500+ students. We started using O365 some odd 3 years ago... main app for co workers and students is Teams.

 

I immediately got interested in SDS to auto create edu teams. At that time there was no coupling available for our SIS system (Magister)... so using the SIS database back end... some Perl glue... some Flow automation I came up with a sync system which works fairly well.

 

One of the flaws is that it's not really capable of dealing with things like network outages and such which result in an empty set of sections, students and teacher. In such a case all owners and members are removed from the teams. This was startling at first but is also self repairing by doing an new (manual) sync. (Yes I know... have to build in something for that event).

 

Up to this year that is.... this school year had 2 special things:

- teacher started using private channels

- for some reason we've had 2 network outages, which are rare.

 

And there is a problem with private channels: their owners and members are not restored after a new good sync. My guess would be that there is no information which owners and members should be added.

 

So I wrote a little PS (enclosed below) script which adds the team owners as owner of the private channel. Adding members is left to the owners (usually teachers). Not perfect... but something at least. MS Support did not have help on this subject, and I am still waiting on SDS support.

 

The script uses functions from the preview Teams module. It takes a CSV file with one column as input: the SIS ids of the teams involved. I can make this list from within my sync system. But you can adapt it for your environment off course.

 

Hope this helps people having simular problems

 

Peter

 

script added below

 

# HiddenChannelsOwners
# p.kaagman@atlascollege.nl

# Due to a sync error our edu teams were left without owners and student.
# After a restore of the sync all owners and student are once again added
# to the correct teams with all files, chats and such intact.
#
# But not the private channels, these are left without owners or members.
#
# This script partly restores ownership of these channels.
# Ownership to the private channels is given to the team owners. I was not
# able to find any information about membership. It's left to the owners to
# add the members to the private channels

# Edu teams are identified by sis_id. A csv file containing those is exported from
# our sync system. That way we only process the edu teams of interest.
$sis_ids = Import-Csv -Delimiter ";" -Path C:\Users\pkn\powershell\sections_2209.txt

foreach ($line in $sis_ids){
  # The MailNickName is used to identify the teams.
  # This name is composed as follows "Section_[sis_id]
  $mailnick = "Section_"+$line.sis_id
  # Get an object with the information of that team
  $team = Get-Team -MailNickName $mailnick
  # Get a list of owners for that team
  # These will be used to restore ownership
  $TeamOwners = Get-TeamUser -GroupId $team.GroupId -Role Owner
  Get a list of channels for that team
  $channels = Get-TeamChannel -GroupId $team.GroupId
  # Itterate through that list of channels
  foreach ($channel in $channels){
    # We are only interested in private channels
    if ($channel.MembershipType -eq "Private"){
      # Get a list of owners for that channel
      # A private channel is identified by:
      # - The groupid of the team
      # - The DisplayName of the channel
      $ChannelOwners = Get-TeamChannelUser -GroupId $team.GroupId -DisplayName $channel.DisplayName -Role Owner 
      # Only interested in channels without an owner
      if ( -Not ($ChannelOwners) ){
        # Report for debug if such a channel is found
        $tmp = "Team: "+$team.DisplayName+" Channel: " +$channel.DisplayName + " has no owners"
        Write-Output $tmp
        # Add the team owners as new owner of the pricate channel
        foreach ($TeamOwner in $TeamOwners){
          # TeamOwners allways has an owner without a name... skip that one
          if ($TeamOwner.User) {
            # Report for debug reasons
            $TeamOwner.User
            # A private channel is identified by:
            # - The groupid of the team
            # - The DisplayName of the channel
            # First add the TeamOwner as member
            Add-TeamChannelUser -GroupId $team.GroupId -DisplayName $channel.DisplayName -User $TeamOwner.User
            # After being added the user can be promoted to owner
            Add-TeamChannelUser -GroupId $team.GroupId -DisplayName $channel.DisplayName -User $TeamOwner.User -Role Owner
          }
        }
      }
    }
  }
}

 

0 Replies