locked
Update OnlyAllowMembersViewMembership setting of a Sharepoint group using Powershell RRS feed

  • Question

  • Hi,

    I want to change the Allow Only members to view group (Who can view the membership of the group?) setting of a sharepoint group. How can I achive that? In .Net object Model we have 'OnlyAllowMembersViewMembership' property for Sharepoint group. Is there any property like it in powershell?

    Thanks

     

     

     

     

    Thursday, June 23, 2011 6:53 AM

Answers

  • Hi RonakJ,

    Actually, we start to support PowerShell for SharePoint from SharePoint 2010. In SharePoint 2007, in order to use PowerShell to update properties of SharePoint, we need to involve the SharePoint object models from PowerShell as shown below:

    [System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
    [System.Reflection.Assembly]::Load(“Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
    $spsite=[Microsoft.SharePoint.SPSite](“http://localhost/sites/intranet“)
    $spweb = $spsite.openweb()
    $group = $spweb.Groups["SPGroupOnlyAllowMembers"]
    $group.OnlyAllowMembersViewMembership = $true
    $group.update()
    $spweb.update()

    If you have any more questions, please feel free to ask.

    Thanks,
    Jinchun Chen


    Jinchun Chen Forum Support Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff AT microsoft.com(Please replace AT with @)
    • Marked as answer by Wayne Fan Monday, July 4, 2011 2:06 AM
    Tuesday, June 28, 2011 6:13 AM
    Moderator

All replies

  • Hi RonakJ,

    Actually, we start to support PowerShell for SharePoint from SharePoint 2010. In SharePoint 2007, in order to use PowerShell to update properties of SharePoint, we need to involve the SharePoint object models from PowerShell as shown below:

    [System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
    [System.Reflection.Assembly]::Load(“Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
    $spsite=[Microsoft.SharePoint.SPSite](“http://localhost/sites/intranet“)
    $spweb = $spsite.openweb()
    $group = $spweb.Groups["SPGroupOnlyAllowMembers"]
    $group.OnlyAllowMembersViewMembership = $true
    $group.update()
    $spweb.update()

    If you have any more questions, please feel free to ask.

    Thanks,
    Jinchun Chen


    Jinchun Chen Forum Support Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff AT microsoft.com(Please replace AT with @)
    • Marked as answer by Wayne Fan Monday, July 4, 2011 2:06 AM
    Tuesday, June 28, 2011 6:13 AM
    Moderator
  • Thanks Chen. Thats exactly I want
    Wednesday, June 29, 2011 6:26 AM
  • In Powershell script for Sharepoint 2010 Site I have written the following code:

    $newGroup = $spWeb.SiteGroups[$groupName]

    $newGroup.OnlyAllowMembersViewMembership = $false

    $newGroup.Update()

    $spWeb.Update()


    Wednesday, June 29, 2011 6:30 AM
  • Thanks for this post, we do need to update the configuration setting for 'who cna view the membership of the group?' field in about 1000 groups. I cant seem to be able to gain access to the right node.

    PS $web.SiteGroups.Add("$web Test1", $web.Site.Test1, $web.Site.Test1, "Use this group to grant people full control permissions to the $web site")

    Exception calling "Add" with "4" argument(s): "Value does not fall within the expected range."
    At line:1 char:20
    + $web.SiteGroups.Add <<<< ("$web Test1", $web.Site.Test1, $web.Site.Test1, "Us
    e this group to grant people full control permissions to the $web site")
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException


    mfn

    Friday, March 9, 2012 12:42 PM
  • to make the change on an entire Sharepoint 2010 farm, try this:

    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
    
    $site = Get-SPSite("http://localhost");
    
    foreach($subweb in $site.AllWebs){
        write-host "Acquired Site [$subweb]" -backgroundcolor DarkYellow -foregroundcolor black
        foreach($group in $subweb.Groups)
        {
            write-host $group.Name -BackgroundColor green -foregroundcolor black
            $group.OnlyAllowMembersViewMembership = $false;
            $group.Update();
        }
        $subweb.Dispose();
    }
    
    $site.Dispose();
    
    
    

    Wednesday, December 19, 2012 12:27 PM
  • In Powershell script for Sharepoint 2010 Site I have written the following code:

    $newGroup = $spWeb.SiteGroups[$groupName]

    $newGroup.OnlyAllowMembersViewMembership = $false

    $newGroup.Update()

    $spWeb.Update()



    Hi, I'm trying to do a similar thing, but only want to allow this setting for one of my groups I.e. if group name ends in owner, only allow members to view membership. Any ideas please? Thank you
    Saturday, March 16, 2013 6:55 AM
  • Hi Chen,

    I have tried the below code it executing without errors in sharepoint online management shell. but after execution the property of "Who can view the membership of the group?" is still set to Group Members. i want to change it to Everyone. It is not reflecting in sharepoint site.

    Code snippet:

    foreach ($spgroup in $sGroups)
    {     
    Write-host $spgroup.Title
    if($spgroup.Title -like "*Contribute*" -Or $spgroup.Title -like "*SuperAdmin*" -Or $spgroup.Title -like "*ViewOnly*")
    {
    Write-Host "Updating OnlyAllowMembersViewMembership for group:" $spgroup.Title -foregroundcolor Yellow
    $spgroup.OnlyAllowMembersViewMembership = $false;
    $spgroup.update()
    $sGroups.update()
    $web.update()
    } }

    Wednesday, February 7, 2018 3:38 PM