Unable to update privacy for "class" style Teams

Copper Contributor

I've been attempting to figure out how to make all of our Teams private for a while now. Couldn't figure out for the life of me why the option wasn't available until I figured out that there are different types of Teams, the vast majority of which that we use are "class" style, and each type works differently for setting to private/public. The problem with "class" style teams is that they don't allow for setting them to private via the GUI, so I turned to PowerShell. I wrote a little script to broadly grab every team (of which we have a few) and set them all to Private.

 

The script:

$team = Get-Team

foreach ($team in $team) {
    Set-Team -GroupId $team.GroupId -Visibility Private
}

 

It worked for a handful of Teams but the vast majority threw an error and I cannot figure out how to remedy the problem.

Set-Team : Error occurred while executing 
Code: Request_BadRequest
Message: Visibility of a group with hidden membership cannot be updated.
InnerError:
  RequestId: f803439a-60df-4d7d-86a3-2ba5c9062e12
  DateTimeStamp: 2021-03-09T19:43:13
HttpStatusCode: Request_BadRequest
At line:4 char:5
+     Set-Team -GroupId $team.GroupId -Visibility Private
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-Team], ApiException
    + FullyQualifiedErrorId : Microsoft.TeamsCmdlets.PowerShell.Custom.ErrorHandling.ApiException,Microsoft.TeamsCmdlets.PowerShell.Custom.SetTeam

 

It appears to be related to how most of the teams have a "hidden membership" but I cannot determine how to unhide the membership or force the script to change the privacy setting regardless. I have to change the privacy for our Teams to Private one way or another to prevent students from "Team hopping" so any help for either my PowerShell solution or some other way (aside from manually changing the settings for 500+ teams, preferably) would be appreciated.

0 Replies