Set Office 365 Group Privacy to Private or Public using PowerShell

Requirement: Change Office 365 Group Privacy to Private or Public (or vice versa!).

How to Change Office 365 Group Privacy?

Microsoft 365 groups are a powerful tool for collaboration and communication within an organization. It’s crucial to understand how the privacy setting works in Microsoft 365 groups. By default, the privacy is set to public, which means that anyone in your organization can find and join the group. If you want to keep the group private so that only specific people can join and only members can access the group, you’ll need to change the group’s privacy setting. In this article, we’ll show you how to change Microsoft 365 Group privacy from public to private (or vice versa!)

You can change the Office 365 group’s privacy through the Microsoft 365 admin center as an admin. Here is how:

  1. Log in to the Microsoft 365 Admin Center site: https://admin.microsoft.com using your admin credentials.
  2. Expand “Teams & Groups” and Click on “Active Teams & Groups” in the left navigation.
  3. Search and select the Office 365 group you wish to change the privacy settings.
  4. Click on the settings tab, and then select the privacy to “Private” or “Public”.
  5. Click on “Save” to commit your changes. You should see the “Changes saved” message.
    change office 365 group privacy to private or public using powershell

Please note, changing a group from public to private will remove it from the public directory and make it invisible to non-members. Similarly, changing a group from private to public will make it visible to everyone in the organization, including non-members

PnP PowerShell to Change the Microsoft 365 Group Privacy

Let’s change a Microsoft 365 group from Private to Public using PnP PowerShell:

#Config Variables
$AdminSiteURL = "https://crescent-admin.sharepoint.com"
$GroupEmail = "HRAdmin@crescent.com"

Try {
    #Connect to PnP Online
    Connect-PnPOnline -Url $AdminSiteURL -Interactive

    #Get the Office 365 Group from Email
    $Group = Get-PnPMicrosoft365Group | Where Mail -eq $GroupEmail

    #Check if group exists
    If($Group -ne $Null)
    {
        #Set the Group Privacy to Public
        Set-PnPMicrosoft365Group -Identity $Group -IsPrivate:$False
        Write-Host "Group Privacy Updated Successfully!" -f Green
    }
    Else
    {
        Write-host "Could not Find Group!" -f Yellow
    }
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}

Set Office 365 Group Privacy to Private or Public using PowerShell:

Let’s change the privacy of the “Accounts@CrescentTech.com” group to “Private”.

#Get Credentials to connect
$Credential = Get-Credential
 
#Connect to Exchange Online
Connect-ExchangeOnline -Credential $Credential -ShowBanner:$False

#Set Office 365 group's privacy to "Private"
Set-UnifiedGroup -Identity "Accounts@CrescentTech.com" -AccessType Private

#Disconnect Exchange Online
Disconnect-ExchangeOnline -Confirm:$False

Similarly, you can change the group type to “Public” as:

Set-UnifiedGroup -Identity "Accounts@TheCrescentTech.com" -AccessType Public

To change a SharePoint Online site privacy, use: How do I make a SharePoint site public to everyone?

In summary, changing a Microsoft 365 group from private to public can be a useful way to allow non-members to view and participate in group conversations and access resources. By following the steps outlined in this guide, you can easily change the privacy settings of a Microsoft 365 group in just a few clicks. You can also automate the process with the PowerShell scripts provided in this post.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

3 thoughts on “Set Office 365 Group Privacy to Private or Public using PowerShell

  • This is what I used to change a specific group
    # Install and import the Exchange Online Management Module if not already done
    >> Install-Module -Name ExchangeOnlineManagement -Force -SkipPublisherCheck
    >> Import-Module ExchangeOnlineManagement
    >>
    >> # Connect to Exchange Online
    >> Connect-ExchangeOnline
    >>
    >> # Specify the identity of the specific group you want to change
    >> $groupIdentity = “youremail@domain.com”
    >>
    >> # Set the privacy setting to “Private” for the specified group
    >> Set-UnifiedGroup -Identity $groupIdentity -AccessType Private
    >>
    >> # Disconnect Exchange Online
    >> Disconnect-ExchangeOnline -Confirm:$False

    This is what I came up with to change all groups

    # Connect to Exchange Online
    Connect-ExchangeOnline

    # Get all Office 365 groups
    $groups = Get-UnifiedGroup

    # Filter public groups and set their privacy to “Private”
    foreach ($group in $groups) {
    if ($group.AccessType -eq “Public”) {
    Set-UnifiedGroup -Identity $group.Identity -AccessType Private
    Write-Output “Changed privacy setting to Private for group: $($group.DisplayName)”
    }
    }

    # Disconnect Exchange Online
    Disconnect-ExchangeOnline -Confirm:$False

    Reply
  • Hi , thank you for this. What if we want to edit multiple groups at once , how would the code change? , and | did not work

    Thanks,

    Reply
    • Wrap the groups in an array and use the cmdlet as:
      $Groups = “Group1@Domain.com”, “Group3@Domain.com”, “Group3@Domain.com”
      $Groups | ForEach-Object { Set-UnifiedGroup -Identity $_ -AccessType Public }

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *