PowerShell启用Active Directory回收箱, Windows Server 2012/2012R2/2016/2019中的工作.
1. Enabling Recycle Bin (Windows服务器 2008 R2):
To enable recycle bin:
- 在PDC上打开PowerShell (主要域控制器).
笔记: 确认哪个服务器是主要DC, run the below command:
Get-ADForest | fl
- 确保您使用的服务器是schemamaster,否则命令将无法工作. 检查ForestMode是否显示为Windows2008R2Forest. 如果不, 运行导入模块ActiveDirectory, 然后运行以下命令:
Set-ADForestMode –Identity <yourdomainname> -ForestMode Windows2008R2Forest
- 通过右键单击顶级项目并选择提高森林功能级别,可以使用Active Directory域和信托启用它. 请注意,如果存在一个或多个DC,此选项需要复制, 因此,运行PowerShell命令会产生更快的结果.
- 启用后,在PowerShell中运行以下命令:
Enable-ADOptionalFeature –Identity 'CN=Recycle Bin
Feature,CN=Optional Features,CN=Directory Service,CN=Windows
NT,CN=Services,CN=Configuration,DC=domain' –Scope
ForestOrConfigurationSet –Target '<yourdomainname>'
By default, 已删除的对象寿命和广告中的墓碑寿命设置为 60 days. 如果这还不够, 您可以通过运行以下命令来修改值 (以下示例将它们设置为 1 year):
Set-ADObject -Identity “CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=domain” –Partition "CN=Configuration,DC=contoso,DC=com" –Replace:@{"tombstoneLifetime" = 365}
Set-ADObject -Identity "CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=domain" –Partition "CN=Configuration,DC=domain" –Replace:@{"msDS-DeletedObjectLifetime" = 365}
2. 如何还原对象:
First, 使用以下命令之一使用PowerShell搜索对象. 别忘了运行命令:
Import-Module ActiveDirectory
搜索所有对象:
get-adobject -filter 'IsDeleted -eq $True' -IncludeDeletedObjects
-properties IsDeleted,LastKnownParent | Format-List
Name,IsDeleted,LastKnownParent,DistinguishedName
搜索特定用户:
Get-ADObject -Filter {displayName -eq "Name"} -IncludeDeletedObjects
(where Name is the display name of the user)
一旦找到用户或对象, 使用以下命令恢复它:
Get-ADObject -Filter {displayName -eq "Name"} -IncludeDeletedObjects | Restore-ADObject
这将将其恢复到最后的OU位置
3. Enabling Recycle Bin (Windows Server 2012/2012R2/2016/2019)
在此版本中默认启用. 确认森林功能水平至少为Windows2008R2. Once completed:
- 打开Active Directory管理中心
- 右键单击域名,然后选择“启用Active Directory回收箱”
- 由于此选项更改了广告的收集结构, 提示将表明此操作是不可逆转的. 按确定
- 等待更改应用
- 完毕
4. 如何还原对象 (Windows Server 2012/2012R2/2016/2019):
- 恢复对象:
- Open 活动目录管理中心;
- 单击域名文件夹,然后打开 删除对象 列表中的文件夹;
- 找到对象并选择 Restore. 这将自动将其恢复到删除对象的位置;
- 在另一个文件夹或OU中恢复对象, select 还原到;
- 完毕