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

[玩转系统] 如何使用 PowerShell 更改 SharePoint 组所有者?

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

如何使用 PowerShell 更改 SharePoint 组所有者?


在 SharePoint 网站中更改组所有者:

您是否曾经需要更改 SharePoint 组的所有者?也许有人离开了公司,您需要将所有权转让给另一个用户。 PowerShell 可以提供帮助!在这篇博文中,我将向您展示如何使用 PowerShell 更改 SharePoint 组的所有者。

请按照以下步骤更新 SharePoint 中的 SharePoint 组所有者。

  • 转到网站设置>>人员和群组
  • 从左侧导航中选择您想要的组
  • 在群组页面中,单击设置>>群组设置>>在“群组所有者”字段中设置新的群组所有者。点击“确定”保存您的更改。这会更改该组的所有者。

[玩转系统] 如何使用 PowerShell 更改 SharePoint 组所有者?

从 SharePoint Web 用户界面更改组所有者非常简单。但有时,您可能必须在多个网站集中用新用户替换现有组所有者。理想情况下,我们必须利用 PowerShell 来执行此类管理任务。让我们通过 PowerShell 更改 SharePoint 组所有者。

如何使用 PowerShell 更改 SharePoint 组所有者?

以下是用于更新组所有者的 SharePoint PowerShell。您需要具有场管理员或网站集管理员权限才能更改组所有者。


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Parameters
$SiteURL="https://intranet.crescent.com/Sites/Operations"
$GroupName="Operations Site Owners"
$GroupOwner="Crescent\Salaudeen"

Try {
    #Get the Site and Group
    $Web = Get-SPWeb $SiteURL
    $Group = $web.SiteGroups[$GroupName]

    if ($Group -ne $null)
    {  
        #Get the User 
        $Owner = $web.EnsureUser($GroupOwner)

        #change group owner
        $Group.Owner = $Owner

        #Update the Group
        $Group.Update()
        Write-host -f Green "Group Owner updated successfully!"
    }
    else
    { 
        Write-host -f Yellow "Group Doesn't Exist!" 
    }
}
Catch {
    write-host -f Red "Error Changing Group Owner!" $_.Exception.Message
}

此 PowerShell 脚本以编程方式更改给定组名称的组所有者。默认情况下,您只能指定一个用户作为组所有者,因此最好将组所有者设置为 Farm 管理员帐户或使用 SharePoint 组作为组所有者!

使用 PowerShell 更新所有组的 SharePoint 组所有者:

虽然上面的脚本更改了给定组名称的组所有者,但让我们更改整个网站集中所有组的组所有者。以下是用于为网站集中的所有组设置组所有者的 PowerShell 脚本。


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Parameters
$SiteURL="https://intranet.crescent.com/Sites/Sales"
$GroupOwner="Crescent\Salaudeen"

Try {
    #Get all sites under given Site Collection
    $WebsCollection =  Get-SPSite $SiteURL | Get-SPWeb -Limit ALL
    
    #Loop through each web
    Foreach ($Web in $WebsCollection) 
    {
        Write-Host -f Yellow "Processing Web:"$Web.URL
        
        #Process the sites with unique permissions
        If($Web.HasUniqueRoleAssignments)
        {
            #Get the Group Owner User
            $Owner = $Web.EnsureUser($GroupOwner)

            #Get all Groups and Iterate through
            Foreach ($Group in $Web.Groups)
            {
                #Update the group owner                    
                $Group.Owner = $Owner
                $Group.Update()
                Write-host -f Green "Group Owner Updated for "$Group.Name
            }
        }
    }
}
Catch {
    write-host -f Red "Error Changing Group Owner!" $_.Exception.Message
}

尽管编写此脚本是为了更改给定网站集的所有组所有者,但对此脚本稍作更改,您就可以更改任意数量网站集的 SharePoint 组的组所有者。您还可以对脚本进行一些更改,以更改整个 Web 应用程序甚至场中所有 Web 应用程序的组所有者。只需将 $WebsCollection 更改为:


$WebsCollection =  Get-SPWebApplication | Get-SPSite  -Limit ALL | Get-SPWeb -Limit ALL
提示:您还可以将现有的 SharePoint 组指定为 SharePoint 中的组所有者!方法如下:
$GroupOwner=$web.SiteGroups[“销售网站所有者”]

这是使用 PowerShell 更改 SharePoint Online 中的组所有者的另一篇文章:如何使用 PowerShell 更改 SharePoint Online 组所有者?

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

取消回复欢迎 发表评论:

关灯