Forum Discussion

Curious_Kevin16's avatar
Curious_Kevin16
Brass Contributor
Oct 17, 2024

Convert large number of Public Teams to Private

Howdy Folks,

 

We currently have a substantial number of public Teams in our environment and would like to convert as many of these to private as possible as part of our security and compliance remediation efforts. Is there a recommended approach for automating this task, potentially using a script? Additionally, what implications should we be aware of as a result of converting these Teams to private?

 

Any advise/help is much much appreciated!

 

 

  • deanshepherd's avatar
    deanshepherd
    Brass Contributor

    Curious_Kevin16 

     You can use the teams powershell module sothing like this 

     

     

     

    # Install the MicrosoftTeams module if not already installed
    Install-Module -Name MicrosoftTeams -Scope CurrentUser
    
    # Import the module
    Import-Module MicrosoftTeams
    
    # Connect to Microsoft Teams
    $credential = Get-Credential
    Connect-MicrosoftTeams -Credential $credential
    
    # Get the team you want to update
    $teamName = "Your Team Name"
    $team = Get-Team -DisplayName $teamName
    
    if ($team) {
        $teamId = $team.GroupId
    
        # Update the team to private
        Set-Team -GroupId $teamId -Visibility Private
        Write-Output "The team '$teamName' has been updated to private."
    } else {
        Write-Output "Team '$teamName' not found."
    }
    
    # Disconnect from Microsoft Teams
    Disconnect-MicrosoftTeams

     


    For each team you set as private, you are probably going to have to set its membership as well here is how you can do that Set-TeamMemberSettings (MicrosoftTeamsPowerShell) | Microsoft Learn add Set-TeamMemberSettings after Set-Team visibility

     

    hope this helps
    D