SharePoint Online: Set "Who Can View Group Membership" to Everyone using PowerShell

Requirement: Set Who Can View Group Membership to Everyone

How to Set Who Can View Group Membership to Everyone in SharePoint Online?
Follow these steps to change the who can view group membership in SharePoint Online.
  • Go to Site Settings >>  People and Groups
  • Pick the SharePoint Online group you want change the group membership view settings
  • From the group page, Click on Settings >> Group Settings 
  • Under "Group Settings", Set "Who can view the membership of the group? to "Everyone". Hit OK to save your changes.

PowerShell to Set the View Group Membership to Everyone:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Config Variables
$SiteURL="https://crescenttech.sharepoint.com/"
$GroupName="Team Site Members"

Try {
    $Cred= Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials

    #Get the Group
    $Group = $Ctx.web.SiteGroups.GetByName($GroupName)
    $Ctx.Load($Group)
    $Ctx.ExecuteQuery()

    #Set Group settings: Who can view the membership of the group? Everyone 
    $Group.OnlyAllowMembersViewMembership = $False
    $Group.Update()
    $Ctx.ExecuteQuery()

    Write-host "Group Settings Updated" -ForegroundColor Green  
}
Catch {
    write-host -f Red "Error Updating Group Settings!" $_.Exception.Message
}

PowerShell to Set View Group Membership to Everyone for All Groups in SharePoint Online:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Config Variables
$SiteURL="https://crescenttech.sharepoint.com/sites/marketing"

Try {
    $Cred= Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials
    
    #Get all groups of the site
    $Groups = $Ctx.Web.SiteGroups
    $Ctx.load($Groups)
    $Ctx.ExecuteQuery()
    
    #Iterate through each Group - Exclude SharePoint Online System Groups!
    ForEach($Group in $Groups| Where {$_.OwnerTitle -ne "System Account"})
    {
        #Set Group settings: Who can view the membership of the group? Everyone 
        $Group.OnlyAllowMembersViewMembership = $False
        $Group.Update()
        $Ctx.ExecuteQuery()

        Write-host "Group Settings Updated for $($Group.Title)" -ForegroundColor Green  
    }
}
Catch {
    write-host -f Red "Error Updating Group Settings!" $_.Exception.Message
}
SharePoint Online: Set "Who Can View Group Membership" to Everyone using PowerShell SharePoint Online: Set "Who Can View Group Membership" to Everyone using PowerShell Reviewed by Salaudeen Rajack on January 27, 2018 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.