Tech

How to restore a deleted user in Active directory from the AD recycle bin

How to restore a deleted user in Active directory from the AD recycle bin

To restore a deleted user from the Active Directory (AD) Recycle Bin using PowerShell, follow these steps:

  1. Open PowerShell with administrative privileges.
  2. Import the Active Directory module by running the following command:
powershell
Import-Module ActiveDirectory
  1. Connect to the domain controller where the AD Recycle Bin is enabled. Use the following command, replacing “DomainControllerName” with the actual name of your domain controller:
powershell
$DomainController = "DomainControllerName"
$env:ADPS_LoadDefaultDrive = 0
Set-Location AD:
Set-ADServerSettings -ViewEntireForest:$true -PreferredServer $DomainController
  1. Verify the availability of the AD Recycle Bin by running the following command:
powershell
Get-ADOptionalFeature -Filter 'name -like "Recycle Bin Feature"'

Make sure the “Recycle Bin Feature” is listed with the “EnabledScopes” value set to “Forest.”

  1. Restore the deleted user from the AD Recycle Bin by using the following command, replacing “DeletedUser” with the actual name of the deleted user:
powershell
Get-ADObject -Filter 'samAccountName -eq "DeletedUser" -and isDeleted -eq $true' -IncludeDeletedObjects |
Restore-ADObject
  1. Confirm that the user has been restored by running the following command, replacing “RestoredUser” with the actual name of the user:
powershell
Get-ADUser -Identity "RestoredUser"

If the user is successfully restored, you should see the user’s details displayed.

Please note that restoring a deleted user from the AD Recycle Bin requires appropriate permissions, and the AD Recycle Bin feature must be enabled in your Active Directory environment.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button