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

[玩转系统] SharePoint Online:使用 PowerShell 删除组

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

SharePoint Online:使用 PowerShell 删除组


要求:使用 PowerShell 删除 SharePoint Online 组。

如何删除 SharePoint Online 组?

如果您正在寻找一种快速简便的方法来删除 SharePoint Online 中的组,那么本文适合您。只需几个步骤,您就可以使用网络浏览器从您的网站中删除群组。我们还将了解如何使用 PowerShell 删除 SharePoint Online 中的组!

以下是在 SharePoint Online 中删除用户组的方法:

  1. 登录到您的 SharePoint Online 站点 >> 单击“设置”齿轮 >> 单击“站点设置”。
  2. 在“站点设置”页面上,单击“用户和权限”部分下的“人员和组”。
  3. 单击左侧导航中的组名称。您可能需要单击“更多”,然后选择组

    [玩转系统] SharePoint Online:使用 PowerShell 删除组

  4. 在群组页面,点击设置>>群组设置
  5. 在组设置页面上,向下滚动并单击“删除”按钮并确认提示,单击“确定”以删除 SharePoint Online 中的组。

    [玩转系统] SharePoint Online:使用 PowerShell 删除组

这将删除 SharePoint Online 中的用户组。完成这些步骤后,SharePoint 组将从网站中删除,并且其成员将无法再访问与该组关联的资源。

您是否曾经需要删除 SharePoint Online 中的组,但又不想经历浏览 Web 界面的麻烦?当然,让我们使用 PowerShell 删除 SharePoint Online 组!

从站点中删除组也会从站点中删除该组中的用户。

使用Remove-SPOSiteGroup PowerShell cmdlet 删除SharePoint Online 组

使用Remove-SPOSiteGroup cmdlet,您可以从SharePoint Online 网站集中删除现有的SharePoint 组。它要求您传递网站集的 URL 以及要删除的组的名称。例如,要删除您在上一步中创建的安全组,您可以运行以下 PowerShell 行:


#Variables for Admin Center & Site Collection URL
$AdminCenterURL = "https://Crescent-admin.sharepoint.com/"
$SiteURL = "https://Crescent.sharepoint.com/sites/marketing"

#Connect to SharePoint Online
Connect-SPOService -url $AdminCenterURL -Credential (Get-Credential)

#sharepoint online delete group powershell
Remove-SPOSiteGroup -Site "https://Crescent.sharepoint.com/sites/marketing" -Identity "Marketing Managers"

此Remove-SPOSiteGroup cmdlet 从网站集中删除SharePoint Online 组。

SharePoint Online:使用 PowerShell 删除组

以下是使用 PowerShell 删除 SharePoint Online 中的组的 PowerShell:


#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"

#Function to remove a group from site
Function Remove-SPOGroup([String]$SiteURL, [String]$GroupName)
{
    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 by name
        $Group=$Ctx.web.SiteGroups.GetByName($GroupName)
        $Ctx.ExecuteQuery()

        #Remove group from the web
        $Ctx.web.SiteGroups.Remove($Group)

        #Execute the query
        $Ctx.ExecuteQuery()
        write-host -f Green "Group '$GroupName' Deleted Successfully!" $_.Exception.Message
    }
    Catch {
        write-host -f Red "Error Removing Group!" $_.Exception.Message
    }
}
#Config Parameters
$SiteURL="https://crescent.sharepoint.com/sites/projects"
$GroupName="Project Managers"

#Call the function - powershell commands to delete sharepoint online groups
Remove-SPOGroup -SiteURL $SiteURL -GroupName $GroupName

此 PowerShell 删除 SharePoint Online 中的给定组。

使用 PnP PowerShell 删除 SharePoint Online

让我们使用 PowerShell cmdlet Remove-PnPGroup 删除 SharePoint Online 组。


#Config Variables
$SiteURL = "https://Crescent.sharepoint.com/sites/marketing"
$GroupName ="Contributors"

#Get Credentials to connect
$Cred = Get-Credential

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
    
#Delete a Group from site
Remove-PnPGroup -Identity $GroupName -Force

通过执行本文中概述的步骤,您可以快速轻松地删除 SharePoint Online 中的组,并确保其成员无法再访问与该组关联的资源。如果您需要删除错误创建的组,或者不再需要该组并希望将其从站点中删除,这会很有帮助。

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

取消回复欢迎 发表评论:

关灯