当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:使用 PowerShell 将“谁可以查看组成员身份”设置为“每个人”

作者:精品下载站 日期:2024-12-14 14:52:31 浏览:16 分类:玩电脑

SharePoint Online:使用 PowerShell 将“谁可以查看组成员身份”设置为“每个人”


要求:将“谁可以查看组成员身份”设置为“所有人”。

如何在 SharePoint Online 中将谁可以查看组成员资格设置为每个人?

默认情况下,在 SharePoint 中,每个人都可以查看该组的成员身份。但是,在某些情况下,您可能希望将组设置设置为仅允许组成员查看已被授予管理组权限的其他用户。另一方面,您可能希望开放组成员身份以供所有人使用。因此,根据具体的权限要求,您可以设置组设置。

请按照以下步骤更改可以查看 SharePoint Online 中的组成员身份的人员:

  1. 转到网站设置>>人员和群组
  2. 选择要更改组成员身份视图设置的 SharePoint Online 组
  3. 在群组页面中,单击“设置>>群组设置”
  4. 在“群组设置”下,设置“谁可以查看群组的成员资格?”给“每个人”。点击“确定”保存您的更改。

[玩转系统] SharePoint Online:使用 PowerShell 将“谁可以查看组成员身份”设置为“每个人”

PowerShell 将查看组成员身份设置为“Everyone”:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Config Variables
$SiteURL="https://Crescent.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 将 SharePoint Online 中所有组的查看组成员身份设置为每个人:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Config Variables
$SiteURL="https://Crescent.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
}

用于更改组设置的 PnP PowerShell


#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Retail"
$GroupName = "Retail Members"

#Connec tot SharePoint Online
Connect-PnPOnline -URL $SiteURL -Interactive

#Change Group Settings
Set-PnPGroup -Identity $GroupName -OnlyAllowMembersViewMembership:$false

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯