[玩转系统] 管理 Microsoft 365 用户回收站
作者:精品下载站 日期:2024-12-14 05:50:03 浏览:14 分类:玩电脑
管理 Microsoft 365 用户回收站
默认情况下,删除的用户帐户将在 Microsoft Entra ID 回收站中保留 30 天。它被描述为软删除,因为您可以恢复 Microsoft 365 用户帐户。 30 天后,Microsoft 将从回收站中永久删除所有已删除的用户帐户,这称为硬删除。在本文中,您将了解如何管理回收站中已删除的 Microsoft 365 用户。
软删除与硬删除 Microsoft 365 用户
当我们删除用户帐户时,它将移至 Microsoft Entra ID 中的回收站 30 天。删除 Microsoft 365 用户的方法有两种:
- 软删除用户是指当您删除用户时,该用户会移至 Microsoft Entra ID 回收站
- 硬删除用户是指当您永久删除用户时,该用户也会从 Microsoft Entra ID 回收站中删除
注意:只有在没有其他选项可用时,才应将硬删除用作最后的选择。一旦硬删除用户,就无法恢复该用户或与该用户关联的任何数据。
管理 Microsoft 365 回收站已删除的用户
让我们研究一下管理 Microsoft 365 已删除用户的不同方法:
- 在回收站中查找已删除的用户
- 恢复删除的用户最多 30 天
- 从回收站移除已删除的用户
- 导出已删除用户帐户的信息
连接到 Microsoft Graph PowerShell
为了能够运行当前文章中指定的 PowerShell 命令,您需要安装 Microsoft Graph PowerShell。
以管理员身份启动 Windows PowerShell 并运行以下 PowerShell cmdlet。
Install-Module Microsoft.Graph -Force
然后,使用以下权限连接到 Microsoft Graph PowerShell。
Connect-MgGraph -Scopes "User.ReadWrite.All"
现在,您已准备好使用 Microsoft Graph PowerShell 命令。
在回收站中查找已删除的 Microsoft 365 用户
我们将向您展示如何在 Microsoft Entra 管理中心的回收站中以及使用 PowerShell 查找已删除的用户。
在 Microsoft Entra 中查找所有已删除的用户
要在 Microsoft Entra 管理中心查找已删除的用户帐户,请按照以下步骤操作:
- 登录 Microsoft Entra 管理中心
- 展开身份
- 单击用户 > 已删除的用户
它显示所有 Microsoft 365 已删除用户的列表。
获取特定的 Microsoft 365 已删除用户帐户
使用 PowerShell 连接到 Microsoft Entra ID 后,您可以获得 Microsoft 365 已删除的用户。我们将使用 Get-MgDirectoryDeletedItemAsUser cmdlet 来获取有关单个用户的信息。
请参阅下面的 PowerShell 命令语法。您应该使用对象 ID 编号。
Get-MgDirectoryDeletedItemAsUser -DirectoryObjectId "Object ID Number"
运行以下 PowerShell 命令示例以显示有关已删除用户的信息。
Get-MgDirectoryDeletedItemAsUser -DirectoryObjectId "b4eda5c3-2081-4e47-816c-1e3270be079a"
PowerShell 输出显示有关特定用户的信息。
DisplayName Id Mail UserPrincipalName
----------- -- ---- -----------------
Melissa Kelly b4eda5c3-2081-4e47-816c-1e3270be079a [email protected]
获取所有 Microsoft 365 已删除用户帐户的列表
使用 Get-MgDirectoryDeletedItemAsUser cmdlet 通过以下脚本查找所有 Microsoft 365 已删除用户。
# Connect with privileges
Connect-MgGraph -Scopes "User.ReadWrite.All"
# Retrieve deleted directory items
$DeletedItems = Get-MgDirectoryDeletedItemAsUser -All -Property 'Id', 'userPrincipalName', 'displayName'
# Check if there are no deleted accounts
if ($DeletedItems.Count -eq 0) {
Write-Host "No deleted accounts found in the recycle bin." -ForegroundColor Cyan
}
else {
# Create an array to store the report
$Report = @()
# Loop through the deleted items
foreach ($Item in $DeletedItems) {
# Create a custom object for each item and add it to the report
$ReportLine = [PSCustomObject]@{
Id = $Item.Id
UserPrincipalName = $Item.UserPrincipalName
'Display Name' = $Item.DisplayName
}
$Report += $ReportLine
}
# Sort the report by 'Display Name'
$Report | Sort-Object 'Display Name' | Ft Id, UserPrincipalName, 'Display Name'
}
在我们的示例中,PowerShell 输出如下所示。
Id UserPrincipalName Display Name
-- ----------------- ------------
0de964ae-f09a-4e65-bc8c-cbeac2745e4c [email protected] Adam Mackay
d23f1e98-02db-4292-98aa-6f511c433f1b [email protected] Alexander Manning
2beda4b9-559b-4d39-9415-51ce47f2963f [email protected] Benjamin May
1a1fd41c-ca5f-4432-8313-7a662576856b [email protected] Julia Wood
b4eda5c3-2081-4e47-816c-1e3270be079a [email protected] Melissa Kelly
85df102b-1330-4359-8e6b-240677b26454 [email protected] René Gibs
8b31d6a0-6d92-4b5b-80bd-a4029e641d35 [email protected] RoomMailboxTest
c54f356c-cf90-4d81-ae14-9523adf09084 [email protected] Søren Larsen
7db784ec-87d3-4699-92d0-e4206d0ab44c [email protected] Test User
从回收站恢复已删除的 Microsoft 365 用户
您可以在 Microsoft Entra 管理中心和使用 PowerShell 恢复已删除的用户。
- 您可以从已删除的用户列表中恢复已删除的用户并恢复其数据(日历项目和别名除外),最多 30 天。
- 恢复已删除的用户将恢复所有关联的数据、分配产品许可证并授予他们在被删除之前可以访问的所有服务的访问权限。
在 Microsoft Entra 中恢复已删除的用户
要恢复 Microsoft Entra 管理中心中的用户,请按照以下步骤操作:
- 登录 Microsoft Entra 管理中心
- 展开身份
- 点击用户 > 已删除的用户
- 选择用户(选择一个、多个或所有已删除的邮箱)
- 点击恢复用户
- 单击确定
恢复单个已删除的 Microsoft 365 用户帐户
要恢复用户帐户,我们将使用 Restore-MgDirectoryDeletedItem cmdlet 并指定对象 ID 编号。
在我们的示例中,我们想要恢复用户帐户 [email protected]。
请参阅下面的 PowerShell 命令语法。
Restore-MgDirectoryDeletedItem -DirectoryObjectId "Id Number"
使用以下 PowerShell 命令恢复已删除的用户。
Restore-MgDirectoryDeletedItem -DirectoryObjectId "85df102b-1330-4359-8e6b-240677b26454"
运行上述命令后,您将在 Microsoft Entra 管理中心的身份 > 用户 > 所有用户下找到该用户。
批量还原所有已删除的 Microsoft 365 用户帐户
在 Microsoft 365 管理中心中,您一次只能还原一名用户。通过 PowerShell 脚本,您可以使用 Get-MgDirectoryDeletedItemAsUser 和 Restore-MgDirectoryDeletedItem cmdlet 批量还原所有已删除的 Microsoft 365 用户。
运行以下 PowerShell 脚本以批量还原已删除的 Microsoft 365 用户。
# Connect with privileges
Connect-MgGraph -Scopes "User.ReadWrite.All"
# Retrieve deleted directory items
$DeletedItems = Get-MgDirectoryDeletedItemAsUser -All -Property 'Id', 'displayName'
# Check if there are no deleted accounts
if ($DeletedItems.Count -eq 0) {
Write-Host "No deleted accounts found in the recycle bin." -ForegroundColor Cyan
}
else {
# Restore deleted users
foreach ($Item in $DeletedItems) {
# Restore the user by ID
Restore-MgDirectoryDeletedItem -DirectoryObjectId $Item.Id #-WhatIf
Write-Host "Restored user $($Item.DisplayName)" -ForegroundColor Green
}
Write-Host "Restoration process completed." -ForegroundColor Cyan
}
从回收站中删除已删除的 Microsoft 365 用户
您可以使用 PowerShell 从 Microsoft Entra ID 回收站永久删除已删除的 Microsoft 365 用户。
永久删除 Microsoft Entra 中的用户
要从 Microsoft Entra 管理中心永久删除用户,请按照以下步骤操作:
- 登录 Microsoft Entra 管理中心
- 展开身份
- 点击用户 > 已删除的用户
- 选择用户(选择一个、多个或所有已删除的邮箱)
- 点击永久删除
- 单击确定
从回收站中删除单个已删除的用户帐户
要硬删除用户帐户,我们将使用Remove-MgDirectoryDeletedItem cmdlet 并指定对象 ID 编号。
在我们的示例中,我们将永久删除用户帐户 [email protected]。
使用以下 PowerShell 命令语法。
Remove-MgDirectoryDeletedItem -DirectoryObjectId "Id Number"
运行以下 PowerShell 命令以永久删除单个已删除的用户。
Remove-MgDirectoryDeletedItem -DirectoryObjectId "0de964ae-f09a-4e65-bc8c-cbeac2745e4c"
运行上述命令后,可以验证被删除的用户不在已删除用户列表中。
从回收站批量删除所有已删除的用户帐户
使用以下 PowerShell 脚本从回收站永久删除所有已删除的用户。
# Connect with privileges
Connect-MgGraph -Scopes "User.ReadWrite.All"
# Retrieve deleted directory items
$DeletedItems = Get-MgDirectoryDeletedItemAsUser -All -Property 'Id', 'userPrincipalName', 'displayName'
# Check if there are no deleted accounts
if ($DeletedItems.Count -eq 0) {
Write-Host "No deleted accounts found in the recycle bin." -ForegroundColor Cyan
}
else {
# Create an array to store the deleted user IDs
$DeletedIds = @()
# Loop through the deleted items
foreach ($Item in $DeletedItems) {
$DeletedIds += $Item.Id
# Display the name of the item being deleted
Write-Host "Deleted $($Item.DisplayName)" -ForegroundColor Green
# Hard-delete the items
Remove-MgDirectoryDeletedItem -DirectoryObjectId $Item.Id #-WhatIf
}
}
注意:您是否收到错误或想要永久删除邮箱?阅读文章使用 PowerShell 强制删除 Microsoft 365 邮箱。
检查您是否从回收站中永久删除了已删除的用户。转到 Microsoft Entra 管理中心 > 身份 > 用户 > 已删除的用户。列表应该清晰,如下图所示。
导出已删除 Microsoft 365 用户帐户的信息
您可以将回收站中所有已删除 Microsoft 365 用户的信息导出到单个 CSV 文件。这样,您可以搜索不同的用户并查看他们何时被删除。
将软删除的 Microsoft 365 用户导出到 CSV
我们会将回收站中所有已删除的 Microsoft 365 用户导出到 CSV 文件和 Out-GridView。要批量导出软删除用户的列表,请按照以下步骤操作:
- 创建temp文件夹并将其保存在(C:)驱动器中
- 运行以下 PowerShell 脚本
# Connect with privileges
Connect-MgGraph -Scopes "User.ReadWrite.All"
# Retrieve deleted directory items
$DeletedItems = Get-MgDirectoryDeletedItemAsUser -All -Property 'Id', 'userPrincipalName', 'displayName', 'isLicensed', 'deletedDateTime', 'userType'
# Check if there are no deleted accounts
if ($DeletedItems.Count -eq 0) {
Write-Host "No deleted accounts found in the recycle bin." -ForegroundColor Cyan
}
else {
# Create an array to store the report
$Report = @()
# Loop through the deleted items
foreach ($Item in $DeletedItems) {
$DeletedDate = Get-Date($Item.DeletedDateTime)
$DaysSinceDeletion = (New-TimeSpan $DeletedDate).Days
# Create a custom object for each item and add it to the report
$ReportLine = [PSCustomObject]@{
Id = $Item.Id
UserPrincipalName = $Item.UserPrincipalName
'Display Name' = $Item.DisplayName
Deleted = $DeletedDate
'Days Since Deletion' = $DaysSinceDeletion
Type = $Item.UserType
}
$Report += $ReportLine
}
# Sort the report by 'Display Name'
$Report | Sort-Object 'Display Name' | Select-Object Id, UserPrincipalName, 'Display Name', Deleted, 'Days Since Deletion' | Out-GridView
$Report | Sort-Object 'Display Name' | Select-Object Id, UserPrincipalName, 'Display Name', Deleted, 'Days Since Deletion' | Export-CSV "C:\temp\DeletedMicrosoft365users.csv" -NoTypeInformation -Encoding UTF8
}
- 运行上面的脚本后,会出现Out-GridView
- 使用 Microsoft Excel 等应用程序打开 CSV 文件
- 转至数据 > 来自文本/CSV,然后选择 C:\temp 文件夹中的 CSV 文件
- 检查分隔符是否设置为逗号,然后单击加载
- 查看回收站中所有软删除的 Microsoft 365 用户的详细列表
这是否有助于您管理 Microsoft 365 用户?
了解更多:为 Microsoft 365 用户重置 MFA »
结论
您了解了如何管理 Microsoft Entra ID 回收站中的 Microsoft 365 用户。 Microsoft 将在 30 天后自动删除已删除的用户(硬删除)。您可以批量还原软删除的用户或从 Microsoft Entra ID 回收站永久删除用户。此外,您还可以使用 PowerShell 将所有已删除的 Microsoft 365 用户的信息导出到 CSV 文件。
您喜欢这篇文章吗?您可能还喜欢导出 Microsoft 365 用户许可证。不要忘记关注我们并分享这篇文章。
猜你还喜欢
- 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