SharePoint Online:使用 PowerShell 更改组所有者
SharePoint 组通过将一组用户分配到一个组并通过该组向他们分配权限来简化权限管理。当我们创建网站时,网站的默认所有者组(例如,在“营销”网站上,其“营销所有者”)被指定为所有组的组所有者。如果有人创建自定义组,则创建者将被指定为组所有者。
如何更改 SharePoint Online 中的组所有者?
如果您是 SharePoint Online 网站的管理员并且需要更改组所有者,则需要执行一些步骤。在这篇博文中,我们将引导您完成在 SharePoint Online 中更改组所有者的过程。如果您需要将组的所有权转移给另一个用户,这可能是一个有用的过程。
请按照以下步骤更改 SharePoint Online 中组的所有者:
- 转至网站设置 >> 网站权限 >> 人员和组。
- 从左侧导航中选择要更改群组所有者的群组。
- 在群组页面中,单击“设置>>群组设置”。
在“群组所有者”字段中输入新的群组所有者。点击“确定”保存您的更改。这将更改 SharePoint Online 组的所有者。
使用 SharePoint Online Management Shell 设置组所有者:
您可以使用 SharePoint Online 命令行管理程序设置 SharePoint Online 组的所有者。
#Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$SiteURL="https://crescent.sharepoint.com"
$GroupName="Team Site Members"
$OwnerName="Salaudeen@crescent.com"
#Get Credentials to connect to SharePoint Admin Center
$Cred = Get-Credential
#Connect to SharePoint Online Admin Center
Connect-SPOService -Url $AdminSiteURL -credential $Cred
#sharepoint online change group owner powershell
Set-SPOSiteGroup -Site $SiteURL -Identity $GroupName -Owner $OwnerName
PowerShell 在 SharePoint Online 中更改组所有者:
以下是如何使用 PowerShell CSOM 设置 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 Parameters
$SiteURL= "https://crescent.sharepoint.com"
$GroupName="Team Site Members"
$GroupOwnerName="Salaudeen@crescent.com"
#$GroupOwnerName="Team Site Owners"
#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Cred
#Get the Group owner - Can be an another Group or User Account
#$GroupOwner = $Ctx.Web.SiteGroups.GetByName($GroupOwnerName)
$GroupOwner = $Ctx.Web.EnsureUser($GroupOwnerName)
#Get the Group
$Group = $Ctx.Web.SiteGroups.GetByName($GroupName)
#Set the Group Owner
$Group.Owner = $GroupOwner
$Group.Update()
$Ctx.ExecuteQuery()
Write-host -f Green "Group Owner has been Updated!"
}
Catch {
write-host -f Red "Error changing Group Owner!" $_.Exception.Message
}
PowerShell 更改 SharePoint Online 中所有组的组所有者:
让我们更改 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 Parameters
$SiteURL= "https://crescent.sharepoint.com"
$GroupOwnerName="Team Site Owners"
#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Cred
#Get the Group owner - Can be an another Group or User Account
$GroupOwner = $Ctx.Web.SiteGroups.GetByName($GroupOwnerName)
#Get All Groups of the Site
$GroupsColl = $Ctx.web.SiteGroups
$Ctx.Load($GroupsColl)
$Ctx.ExecuteQuery()
#Iterate through each Group - Exclude SharePoint Online System Groups!
ForEach($Group in $GroupsColl | Where {$_.OwnerTitle -ne "System Account"})
{
Write-Host -f Yellow "Changing the Owner of the Group:", $Group.Title
#sharepoint online powershell set group owner
$Group.Owner = $GroupOwner
$Group.Update()
$Ctx.ExecuteQuery()
}
Write-host -f Green "All Group Owners are Updated!"
}
Catch {
write-host -f Red "Error changing Group Owners!" $_.Exception.Message
}
这是有关 SharePoint 本地部署的另一篇文章:如何使用 PowerShell 在 SharePoint 中更改组所有者?
SharePoint Online:使用 PnP PowerShell 更改组所有者
要设置 SharePoint Online 组的组所有者,请使用此 PnP PowerShell cmdlet Set-PnPGroup:
#Config Variables
$SiteURL = "https://Crescent.sharepoint.com/Sales"
$GroupName="Sales Portal Members"
#Group owner variable: Can be existing group or user account Email
$GroupOwner = "Sales Portal Owners" #or Salaudeen@Crescent.com
#Connect PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Set Group Owner
Set-PnPGroup -Identity $GroupName -Owner $GroupOwner
要更改 SharePoint Online 中的网站所有者,请使用:如何使用 PowerShell 更改 SharePoint Online 网站所有者?
