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

[玩转系统] 使用 PowerShell 从 SharePoint 组中删除用户

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

使用 PowerShell 从 SharePoint 组中删除用户


如何从 SharePoint 组中删除用户?

作为 SharePoint 管理员,您可能需要不时从组中删除用户。这可以通过 Web 浏览器界面或 PowerShell 在 SharePoint 网站中完成。在本指南中,我们将引导您完成从 SharePoint 2016 和 2013 中的组中删除用户的过程。我们还将向您展示如何使用 PowerShell 从 SharePoint 组中删除用户。

在 SharePoint Web 界面中,如果您想要从 SharePoint 组中删除用户,请以 SharePoint 管理员身份登录,导航到:

  • 单击“站点设置”齿轮图标 >> 单击“站点设置”
  • 在站点设置页面中,单击“用户和权限”组下的“人员和组”链接

    [玩转系统] 使用 PowerShell 从 SharePoint 组中删除用户

  • 单击要从中删除用户的组,从左侧导航中选择组。

    [玩转系统] 使用 PowerShell 从 SharePoint 组中删除用户

  • 选择用户并单击操作菜单 >> 选择“从组中删除用户”

    [玩转系统] 使用 PowerShell 从 SharePoint 组中删除用户

单击“确定”确认。所选用户现已从 SharePoint 组中删除!

使用 PowerShell 从 SharePoint 组中删除用户:

如果您想从 SharePoint 组中删除用户,此 PowerShell 脚本可以提供帮助:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function RemoveUser-FromGroup($SiteURL, $GroupName, $UserAccount)
{
 try
    {
     $ErrorActionPreference = "Stop"
  
     #Get the Web
     $web=Get-SPWeb $SiteURL
    
     #Get the User to Remove 
     $User  = Get-SPUser -Identity $UserAccount -Web $web

     #Get the Group by its name
     $Group = $Web.sitegroups | Where-Object {$_.Name -eq $GroupName}
     if($Group -ne $null)
     {
         #sharepoint powershell delete user from group
         $Group.RemoveUser($User)
         Write-Host "$($User) Removed from the Group: $($GroupName)"
     }
   }
 catch
    { 
           #Write error message on screen and to a LOG file
           write-host $_.Exception.Message
    }
 finally
    {
           $ErrorActionPreference = "Continue"
    }
}

#Call the function to remove user from SharePoint group
RemoveUser-FromGroup "https://sharepoint.crescent.com/sites/Operations" "Operations Members" "Corp\DaveP"

这将从特定 SharePoint 组中删除给定用户。从网站上的所有组中删除用户怎么样?

从所有 SharePoint 组中删除用户

让我们使用 PowerShell 从 SharePoint 的所有组中删除用户:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function RemoveUser-FromAllGroups($SiteURL, $UserAccount)
{
     #Get the Web
     $web=Get-SPWeb $SiteURL
    
     #Get the User to Remove 
     $User  = $Web.EnsureUser($UserAccount)

     #Iterate through all Groups
     foreach($Group in $Web.Groups)
     {
         $GroupUser = $Group.Users | where {$_.UserLogin -eq $User.UserLogin}
         #Check if user member of the group
         if($GroupUser -ne $null)
         {
            #remove user from sharepoint group using powershell 
            $Group.RemoveUser($User)
            Write-Host "$($User) Removed from the Group: $($Group)"
         }
     }
 }

 #Call the function to remove user from all groups in the site  
 RemoveUser-FromAllGroups "https://intranet.crescent.com" "Crescent\Salaudeen"

Web.Group 与 Web.SiteGroup:
Web.SiteGroups 为您提供网站集的跨网站组集合。这些组可用于网站集中的多个 Web 对象。

Web.Groups 为您提供在特定网站(子网站)上具有某些权限的组。这些组可能在网站上的某个位置拥有权限:例如,权限被破坏的列表或列表项。因此,如果您在没有任何权限的情况下将该组添加到网站,则该组不会出现在 Web.Groups 集合中,但会出现在 Web.SiteGroups 集合中。

这是有关 SharePoint Online 的另一篇文章使用 PowerShell 从组中删除用户:SharePoint Online:使用 PowerShell 从组中删除用户

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

取消回复欢迎 发表评论:

关灯