[玩转系统] 如何使用 PowerShell 从 Office 365 组中删除用户?
作者:精品下载站 日期:2024-12-14 21:13:24 浏览:14 分类:玩电脑
如何使用 PowerShell 从 Office 365 组中删除用户?
要求:使用 PowerShell 从 Office 365 组中删除用户。
如何从 Office 365 组中删除用户?
Microsoft 365 组是组织内部协作和沟通的重要工具。如果您是 Office 365 管理员,有时您可能需要从组中删除用户。本文将向你展示如何使用 PowerShell 和适用于 PowerShell 的 Azure Active Directory 模块从 Office 365 组中删除用户。我们还将向您展示如何使用 Microsoft 365 管理中心从 Office 365 组中删除用户。
使用 Microsoft 365 管理中心从 Microsoft 365 组中删除用户
您可以以管理员身份通过 Microsoft 365 管理中心从任何 Office 365 组中删除成员。具体方法如下:
- 登录 Microsoft 365 管理中心站点:https://admin.microsoft.com
- 展开“团队和组”,然后单击左侧导航中的“活跃团队和组”。
- 搜索并选择您想要删除成员的 Office 365 组。
- 在群组详细信息页面上,单击“成员”选项卡>>选择要删除的用户。
现在,您可以通过单击每个成员旁边的“删除为成员”按钮来删除群组成员。您还可以选择多个用户并一键删除他们。同样,您可以单击“所有者”选项卡来删除群组所有者。
- 完成后点击关闭!
如何删除 Microsoft 365 用户的组成员身份?
您可以继续通过特定用户并删除组成员身份,而不是通过组。具体方法如下:
- 在 Office 365 中打开管理应用程序 >> 在左侧导航窗格中,选择用户 >> 活动用户。
- 搜索要删除的用户,从用户对象中选择三个点,然后选择“管理组”。
在下一个窗口中,选择您要删除的组,然后单击“删除”按钮并确认提示。
PowerShell 从 Office 365 组中删除用户
从 Office 365 组中删除用户的一种快速简便的方法是使用 Azure AD PowerShell。以下是我们如何使用 PowerShell 从 Office 365 组中删除用户:
#Variables
$GroupName = "IT Team"
$UserUPN = "[email protected]"
#Connect to AzureAD
Connect-AzureAD -Credential (Get-Credential)
#Get the Azure AD Group
$AADGroup = Get-AzureADGroup -Filter "DisplayName eq '$GroupName'"
#Get the Azure AD User
$AADUser = Get-AzureADUser -Filter "UserPrincipalName eq '$UserUPN'"
#Remove User from Group
Remove-AzureADGroupMember -ObjectId $AADGroup.ObjectID -MemberId $AADUser.ObjectID
同样,您可以通过 PowerShell 快速从所有 Office 365 组中删除用户,如下所示:
#Variables
$UserUPN = "[email protected]"
#Connect to AzureAD
Connect-AzureAD -Credential (Get-Credential) | Out-Null
#Get all Azure AD Unified Groups
$AADGroups = Get-AzureADMSGroup -Filter "groupTypes/any(c:c eq 'Unified')" -All:$true
#Get the Azure AD User
$AADUser = Get-AzureADUser -Filter "UserPrincipalName eq '$UserUPN'"
#Check each group for the user
ForEach ($Group in $AADGroups)
{
$GroupMembers = (Get-AzureADGroupMember -ObjectId $Group.id).UserPrincipalName
If ($GroupMembers -contains $UserUPN)
{
#Remove user from Group
Remove-AzureADGroupMember -ObjectId $Group.Id -MemberId $AADUser.ObjectId
Write-Output "$UserUPN was removed from $($Group.DisplayName)"
}
}
如何从 CSV 文件中删除 Microsoft 365 组中的多个用户?我的 CSV 文件有一个“UPN”列,其中包含用户的登录 ID。
#Variables
$CSVFile = "C:\Temp\UserList.csv"
#Connect to AzureAD
Connect-AzureAD -Credential (Get-Credential) | Out-Null
#Get all Azure AD Unified Groups
$AADGroups = Get-AzureADMSGroup -Filter "groupTypes/any(c:c eq 'Unified')" -All:$true
#Iterate through each line in CSV
Import-CSV $CSVFile | ForEach-Object {
#Get the UPN
$UPN = $_.UPN
#Get the Azure AD User
$AADUser = Get-AzureADUser -Filter "UserPrincipalName eq '$UPN'"
#Check each group for the user
ForEach ($Group in $AADGroups)
{
$GroupMembers = (Get-AzureADGroupMember -ObjectId $Group.id).UserPrincipalName
If ($GroupMembers -contains $UPN)
{
#Remove user from Group
Remove-AzureADGroupMember -ObjectId $Group.Id -MemberId $AADUser.ObjectId
Write-Output "$UPN is removed from Group '$($Group.DisplayName)'"
}
}
}
使用 Exchange Online PowerShell 删除 Office 365 组成员
我们还可以使用 Exchange Online PowerShell 删除 Microsoft 365 组成员:
#Connect to Exchange Online
Connect-ExchangeOnline -Credential (Get-Credential) -ShowBanner:$false
#PowerShell to remove a Member from office 365 group
Remove-UnifiedGrouplinks -Identity "[email protected]" -LinkType "Members" -Links "[email protected]"
PnP PowerShell 从 Office 365 组中删除成员
使用Remove-PnPMicrosoft365GroupMember cmdlet 从 Microsoft 365 组中删除成员。
#Config Variables
$AdminSiteURL = "https://crescent-admin.sharepoint.com"
$GroupEmail = "[email protected]"
$MemberToRemove = "[email protected]"
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $AdminSiteURL -Interactive
#Get the Office 365 Group from Email
$Group = Get-PnPMicrosoft365Group | Where Mail -eq $GroupEmail
#Check if group exists
If($Group -ne $Null)
{
#Get Group Members
$GroupMembers = Get-PnPMicrosoft365GroupMembers -Identity $Group | Select -ExpandProperty Email
If($GroupMembers -contains $MemberToRemove)
{
#Remove Member from Office 365 group
Remove-PnPMicrosoft365GroupMember -Identity $Group -Users $MemberToRemove
Write-Host "Member removed from the Group Successfully!" -f Green
}
Else
{
Write-Host "Could not find Member in the Group!" -f Yellow
}
}
Else
{
Write-host "Could not Find Group!" -f Yellow
}
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
如果要删除 Microsoft 365 组中的所有成员,请使用 cmdlet:Clear-PnPMicrosoft365GroupMember。
同样,您可以使用Remove-PnPMicrosoft365GroupOwner cmdlet 删除组的所有者:
#Config Variables
$AdminSiteURL = "https://salaudeen-admin.sharepoint.com"
$GroupEmail = "[email protected]"
$OwnersToRemove = "[email protected]"
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $AdminSiteURL -Interactive
#Get the Office 365 Group from Email
$Group = Get-PnPMicrosoft365Group | Where Mail -eq $GroupEmail
#Check if group exists
If($Group -ne $Null)
{
#Get Group Owners
$GroupOwners = Get-PnPMicrosoft365GroupOwner -Identity $Group | Select -ExpandProperty Email
If($GroupOwners -contains $OwnersToRemove)
{
#Remove Owner from Office 365 group
Remove-PnPMicrosoft365GroupOwner -Identity $Group -Users $OwnersToRemove
Write-Host "Owner removed from the Group Successfully!" -f Green
}
Else
{
Write-Host "Could not find Owner in the Group!" -f Yellow
}
}
Else
{
Write-host "Could not Find Group!" -f Yellow
}
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
PnP PowerShell 从 SharePoint Online 网站的关联组中删除用户
当网站与 Microsoft 365 组连接时,可以在组级别管理权限。例如,要从网站中删除用户,您必须将其从组中删除。
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/CorporateBranding"
$UserId= "[email protected]"
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Get the Site
$Site = Get-PnPSite -Includes GroupId
#Remove user from the Site's associated Microsoft 365 Group
Remove-PnPMicrosoft365GroupMember -Identity $Site.GroupId -Users $UserId
Write-host "Removed User from the Associated Microsoft 365 Group!" -f Green
}
Catch {
Write-host -f Red "Error:" $_.Exception.Message
}
同样,要从组所有者中删除用户,请使用以下命令:
Remove-PnPMicrosoft365GroupOwner -Identity $Site.GroupId -Users $UserId
包起来
总之,从 Microsoft 365 组中删除用户是一个简单的过程,可以使用 Microsoft 365 管理中心或 PowerShell 来完成。通过删除不再属于组织或不再需要访问组资源的用户,管理员可以确保组中包含的信息的安全性和隐私性。
猜你还喜欢
- 03-30 [玩转系统] 如何用批处理实现关机,注销,重启和锁定计算机
- 02-14 [系统故障] Win10下报错:该文件没有与之关联的应用来执行该操作
- 01-07 [系统问题] Win10--解决锁屏后会断网的问题
- 01-02 [系统技巧] Windows系统如何关闭防火墙保姆式教程,超详细
- 12-15 [玩转系统] 如何在 Windows 10 和 11 上允许多个 RDP 会话
- 12-15 [玩转系统] 查找 Exchange/Microsoft 365 中不活动(未使用)的通讯组列表
- 12-15 [玩转系统] 如何在 Windows 上安装远程服务器管理工具 (RSAT)
- 12-15 [玩转系统] 如何在 Windows 上重置组策略设置
- 12-15 [玩转系统] 如何获取计算机上的本地管理员列表?
- 12-15 [玩转系统] 在 Visual Studio Code 中连接到 MS SQL Server 数据库
- 12-15 [玩转系统] 如何降级 Windows Server 版本或许可证
- 12-15 [玩转系统] 如何允许非管理员用户在 Windows 中启动/停止服务
取消回复欢迎 你 发表评论:
- 精品推荐!
-
- 最新文章
- 热门文章
- 热评文章
[影视] 黑道中人 Alto Knights(2025)剧情 犯罪 历史 电影
[古装剧] [七侠五义][全75集][WEB-MP4/76G][国语无字][1080P][焦恩俊经典]
[实用软件] 虚拟手机号 电话 验证码 注册
[电视剧] 安眠书店/你 第五季 You Season 5 (2025) 【全10集】
[电视剧] 棋士(2025) 4K 1080P【全22集】悬疑 犯罪 王宝强 陈明昊
[软件合集] 25年6月5日 精选软件22个
[软件合集] 25年6月4日 精选软件36个
[短剧] 2025年06月04日 精选+付费短剧推荐33部
[短剧] 2025年06月03日 精选+付费短剧推荐25部
[软件合集] 25年6月3日 精选软件44个
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电视剧] 欢乐颂.5部全 (2016-2024)
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[影视] 【稀有资源】香港老片 艺坛照妖镜之96应召名册 (1996)
[剧集] 神经风云(2023)(完结).4K
[剧集] [BT] [TVB] [黑夜彩虹(2003)] [全21集] [粤语中字] [TV-RMVB]
[实用软件] 虚拟手机号 电话 验证码 注册
[资源] B站充电视频合集,包含多位重量级up主,全是大佬真金白银买来的~【99GB】
[影视] 内地绝版高清录像带 [mpg]
[书籍] 古今奇书禁书三教九流资料大合集 猎奇必备珍藏资源PDF版 1.14G
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电影] 美国队长4 4K原盘REMUX 杜比视界 内封简繁英双语字幕 49G
[电影] 死神来了(1-6)大合集!
[软件合集] 25年05月13日 精选软件16个
[精品软件] 25年05月15日 精选软件18个
[绝版资源] 南与北 第1-2季 合集 North and South (1985) /美国/豆瓣: 8.8[1080P][中文字幕]
[软件] 25年05月14日 精选软件57个
[短剧] 2025年05月14日 精选+付费短剧推荐39部
[短剧] 2025年05月15日 精选+付费短剧推荐36部
- 最新评论
-
- 热门tag