[玩转系统] 如何将成员添加到 Microsoft 365 组
作者:精品下载站 日期:2024-12-14 05:51:48 浏览:14 分类:玩电脑
如何将成员添加到 Microsoft 365 组
Microsoft 365 组允许一组人员发送电子邮件并共享文件、日历和其他资源。有时您必须更新 Microsoft 365 组成员。在本文中,你将了解如何在 Microsoft Entra 管理中心和 PowerShell 中向 Microsoft 365 组添加成员。
Microsoft 365 组
每个组织最多可以在 Microsoft 365 中创建 500,000 个组。
10 GB per subscribed user
Additional storage purchased (unlimited)Mailbox size50 GB
*只有1,000人可以一起访问群组对话。
注意:用户在 Outlook 中访问非常大的组中的日历和对话时可能会注意到延迟。
如果没有 Microsoft 365 组,请了解如何在 Microsoft Entra 管理中心和使用 Microsoft Graph PowerShell 创建 Microsoft 365 组。
将成员添加到 Microsoft Entra ID 中的 Microsoft 365 组
要将成员添加到 Microsoft Entra 管理中心的 Microsoft 365 组,请按照以下步骤操作:
- 登录 Microsoft Entra 管理中心
- 展开身份 > 组 > 所有组
- 单击列表中的 Microsoft 365 组
- 点击成员
- 点击添加成员
- 选择用户
- 点击选择
您已成功将组成员添加到 Microsoft 365 组。
注意:在 Microsoft Entra 管理中心中,您最多可以选择 100 个用户并将他们添加为成员。因此,如果您想向群组添加超过 100 名成员,则需要重复此步骤。另一种方法是使用 PowerShell 来避免这种情况。
使用 PowerShell 将成员添加到 Microsoft 365 组
我们将展示如何使用 PowerShell 将成员添加到现有 Microsoft 365 组:
- 将单个成员添加到 Microsoft 365 组
- 将多个成员添加到单个 Microsoft 365 组
- 将批量成员添加到单个 Microsoft 365 组
- 将多个成员添加到所有 Microsoft 365 组
- 将单个成员添加到所有 Microsoft 365 组
为此,我们需要使用 New-MgGroupMember PowerShell cmdlet。
连接到 Microsoft Graph PowerShell
在开始之前,您必须安装 Microsoft Graph PowerShell 模块。以管理员身份启动 Windows PowerShell 并运行以下命令。
Install-Module Microsoft.Graph -Force
重要提示:在运行 cmdlet 或脚本之前,请务必安装最新的 Microsoft Graph PowerShell 模块版本,以防止出现错误和不正确的结果。
使用以下范围运行 Connect-MgGraph cmdlet 以通过 Microsoft Graph 进行身份验证。
Connect-MgGraph -Scopes "User.ReadWrite.All", "Group.ReadWrite.All", "GroupMember.ReadWrite.All"
现在一切就绪,您可以通过 Microsoft Graph PowerShell 使用这些命令。
将成员添加到 Microsoft 365 组
您可以使用 New-MgGroupMember PowerShell cmdlet 通过 MS Graph PowerShell 将单个或多个成员添加到 Microsoft 365 组。
在我们的示例中,我们将向 Microsoft 365 组(管理团队)添加多个成员。
请参阅将成员添加到 Microsoft 365 组的 PowerShell 语法。
New-MgGroupMember -GroupId "Group Object Id" -DirectoryObjectId "User Object ID"
运行以下 PowerShell 命令将成员添加到 Microsoft 365 组。
New-MgGroupMember -GroupId "031f52ea-cb97-40fc-ab0f-73598f3fc66d" -DirectoryObjectId "41377e9c-dc47-46c0-b4a5-1d5bbdcb5cc5"
将多个成员添加到 Microsoft 365 组
要将多个成员添加到 Microsoft 365 组,您还可以指定 UserPrincipalName 而不是对象 ID。
- 在脚本顶部键入要添加的用户的 UPN
- 输入组对象 ID
- 运行以下 PowerShell 脚本
$upns = @(
"[email protected]",
"[email protected]",
"[email protected]",
)
$GroupId = "031f52ea-cb97-40fc-ab0f-73598f3fc66d"
$Group = Get-MgGroup -GroupId $GroupId -ErrorAction SilentlyContinue
if ($Group) {
foreach ($upn in $upns) {
$User = Get-MgUser -Filter "userPrincipalName eq '$upn'"
if ($User) {
$UserId = $User.Id
$ExistingMember = Get-MgGroupMember -GroupId $GroupId
if ($ExistingMember.Id -eq $UserId) {
Write-Host "User $($User.UserPrincipalName) already exists in the group." -ForegroundColor Yellow
}
else {
New-MgGroupMember -GroupId $GroupId -DirectoryObjectId $UserId
Write-Host "User $($User.UserPrincipalName) added to the group." -ForegroundColor Green
}
}
else {
Write-Host "User $upn does not exist." -ForegroundColor Red
}
}
}
else {
Write-Host "Group $GroupId does not exist." -ForegroundColor Red
}
将所有成员批量添加到 Microsoft 365 组
您可以将所有成员添加到单个 Microsoft 365 组。使用 MS Graph PowerShell,您可以一次添加 100 多个成员。
- 在第 编号 1 行中指定 Microsoft 365 组 ID
- 运行以下 PowerShell 脚本将所有用户添加到单个 Microsoft 365 组
$GroupId = "031f52ea-cb97-40fc-ab0f-73598f3fc66d"
$Group = Get-MgGroup -GroupId $GroupId -ErrorAction SilentlyContinue
if ($Group) {
$Users = Get-MgUser -All
foreach ($User in $Users) {
$ExistingMember = Get-MgGroupMember -GroupId $GroupId
if ($ExistingMember.Id -eq $User.Id) {
Write-Host "User $($User.UserPrincipalName) already exists in the group." -ForegroundColor Yellow
}
else {
New-MgGroupMember -GroupId $GroupId -DirectoryObjectId $User.Id
Write-Host "User $($User.UserPrincipalName) added to the group." -ForegroundColor Green
}
}
}
else {
Write-Host "Group $GroupId does not exist." -ForegroundColor Red
}
将特定部门的用户添加到 Microsoft 365 组
在我们的示例中,我们希望将营销部门的所有用户添加到 Microsoft 365 组([email protected])。
- 在第 1 行中键入 Microsoft 365 组 ID
- 运行以下 PowerShell 脚本
$GroupId = "031f52ea-cb97-40fc-ab0f-73598f3fc66d"
$Group = Get-MgGroup -GroupId $GroupId -ErrorAction SilentlyContinue
if ($Group) {
$Users = Get-MgUser -All -Filter "Department eq 'Marketing'"
foreach ($User in $Users) {
$ExistingMember = Get-MgGroupMember -GroupId $GroupId
if ($ExistingMember.Id -eq $User.Id) {
Write-Host "User $($User.UserPrincipalName) already exists in the group." -ForegroundColor Yellow
}
else {
New-MgGroupMember -GroupId $GroupId -DirectoryObjectId $User.Id
Write-Host "User $($User.UserPrincipalName) added to the group." -ForegroundColor Green
}
}
}
else {
Write-Host "Group $GroupId does not exist." -ForegroundColor Red
}
它将把营销部门的用户添加到 Microsoft 365 组 ([email protected])。
从 CSV 将多个成员添加到 Microsoft 365 组
您可以从 CSV 文件将多个成员添加到单个 Microsoft 365 组。
创建一个包含两列的 CSV 文件:
- 打开Microsoft Excel
- 输入 UPN 作为第一列的标题
- 指定UserPrincipalName
- 输入 UserID 作为第二列的标题
- 指定成员对象 ID
- 如果 (C:) 驱动器中还没有文件夹 temp,请创建该文件夹
- 将文件命名为 M365users.csv
- 保存类型为 CSV(逗号分隔 (*.csv)
- 点击保存
- 在第 1 行中指定CSV 文件路径
- 在第 2 行中键入 Microsoft 365 组 ID
- 运行以下 PowerShell 脚本
$CsvFilePath = "C:\temp\M365users.csv"
$GroupId = "031f52ea-cb97-40fc-ab0f-73598f3fc66d"
$Group = Get-MgGroup -GroupId $GroupId -ErrorAction SilentlyContinue
if ($Group) {
$CsvUsers = Import-Csv -Path $CsvFilePath
foreach ($CsvUser in $CsvUsers) {
$CsvUserID = $CsvUser.UserId
$User = Get-MgUser -Filter "Id eq '$CsvUserID'" -ErrorAction SilentlyContinue
if ($User) {
$UserId = $User.Id
$ExistingMember = Get-MgGroupMember -GroupId $GroupId
if ($ExistingMember.Id -eq $UserId) {
Write-Host "User $($User.UserPrincipalName) already exists in the group." -ForegroundColor Yellow
}
else {
New-MgGroupMember -GroupId $GroupId -DirectoryObjectId $UserId
Write-Host "User $($User.UserPrincipalName) added to the group." -ForegroundColor Green
}
}
else {
Write-Host "User $CsvUserID does not exist." -ForegroundColor Red
}
}
}
else {
Write-Host "Group $GroupId does not exist." -ForegroundColor Red
}
PowerShell 输出结果显示是否:
- Microsoft 365 组不存在或拼写错误
- 用户已经是 Microsoft 365 组的成员
- 用户已添加到 Microsoft 365 组
- 用户不存在或拼写错误
从 CSV 将成员添加到多个 Microsoft 365 组
您可以从 CSV 文件将现有用户添加到多个 Microsoft 365 组。您需要创建一个包含两列的 CSV 文件。前两列将包含 Microsoft 365 组的列表。第三列和第四列将包含您要添加为成员的用户列表。
创建一个包含四列的 CSV 文件:
- 打开Microsoft Excel
- 输入 GroupName 作为第一列的标题
- 指定 Microsoft 365 组电子邮件
- 输入 GroupID 作为第二列的标题
- 指定 Microsoft 365组 ID
- 输入用户名作为第三列的标题
- 指定成员UserPrincipalName
- 输入 MemberId 作为第四列的标题
- 指定成员对象 ID
请参阅下面的 CSV 文件示例。
- 如果 (C:) 驱动器中还没有文件夹 temp,请创建该文件夹
- 将文件命名为 M365members.csv
- 保存类型为 CSV(逗号分隔 (*.csv)
- 点击保存
- 在第 1 行中指定CSV 文件路径
- 运行以下 PowerShell 脚本
$CsvFilePath = "C:\temp\M365members.csv"
$Csv = Import-Csv $CsvFilePath
foreach ($row in $Csv) {
$GroupId = $Row.GroupId
$MemberId = $Row.MemberId
$Group = Get-MgGroup -GroupId $GroupId -ErrorAction SilentlyContinue
if ($Group) {
$ExistingMember = Get-MgGroupMember -GroupId $GroupId
if ($ExistingMember.Id -eq $MemberId) {
Write-Host "User $MemberId already exists in the group." -ForegroundColor Yellow
}
else {
$User = Get-MgUser -Filter "Id eq '$MemberId'" -ErrorAction SilentlyContinue
if ($User) {
New-MgGroupMember -GroupId $GroupId -DirectoryObjectId $MemberId
Write-Host "User $MemberId added to the group." -ForegroundColor Green
}
else {
Write-Host "User $MemberId doesn't exist" -ForegroundColor Red
}
}
}
else {
Write-Host "Group $GroupId does not exist." -ForegroundColor Red
}
}
PowerShell 输出结果显示是否:
- Microsoft 365 组不存在或拼写错误
- 用户已经是 Microsoft 365 组的成员
- 用户已添加到 Microsoft 365 组
- 用户不存在或拼写错误
从 CSV 将单个用户添加到所有 Microsoft 365 组
要将用户添加到多个 Microsoft 365 组,您需要创建 CSV 文件。
在我们的示例中,我们希望将用户(Amanda Hansen)添加到多个 Microsoft 365 组。
创建一个包含两列的 CSV 文件:
- 打开Microsoft Excel
- 输入组作为第一列的标题
- 指定 Microsoft 365 组主 SMTP 地址
- 输入 ObjectID 作为第二列的标题
- 指定 Microsoft 365 组对象 ID
- 如果 (C:) 驱动器中还没有文件夹 temp,请创建该文件夹
- 将文件命名为M365groups.csv
- 保存类型为 CSV(逗号分隔 (*.csv)
- 点击保存
- 在第 1 行中指定CSV 文件路径
- 在第 2 行中输入用户对象 ID
- 运行以下 PowerShell 脚本
$CsvFilePath = "C:\temp\M365groups.csv"
$UserId = "41377e9c-dc47-46c0-b4a5-1d5bbdcb5cc5"
# Check if the user exists
$User = Get-MgUser -UserId $UserId -ErrorAction SilentlyContinue
if ($User) {
$CsvGroups = Import-Csv -Path $CsvFilePath
foreach ($row in $CsvGroups) {
$GroupId = $Row.ObjectID
$Group = Get-MgGroup -GroupId $GroupId -ErrorAction SilentlyContinue
if ($Group) {
$ExistingMember = Get-MgGroupMember -GroupId $GroupId
if ($ExistingMember.Id -eq $UserId) {
Write-Host "User $UserId already exists in the group." -ForegroundColor Yellow
}
else {
New-MgGroupMember -GroupId $GroupId -DirectoryObjectId $UserId
Write-Host "User $UserId added to the group." -ForegroundColor Green
}
}
else {
Write-Host "Group $GroupId does not exist." -ForegroundColor Red
}
}
}
else {
Write-Host "User $UserId does not exist." -ForegroundColor Red
}
就是这样!
阅读更多内容:如何使用 PowerShell 将成员添加到通讯组 »
结论
您了解了如何在 Microsoft Entra 管理中心和使用 PowerShell 将成员添加到 Microsoft 365 组。可以使用这两种方法将单个、多个或所有用户添加为 Microsoft 365 组的成员。如果要将成员添加到多个 Microsoft 365 组,最好创建 CSV 文件并使用 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