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:
- Open PowerShell with administrative privileges.
- Import the Active Directory module by running the following command:
powershell
Import-Module ActiveDirectory
- 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
$env:ADPS_LoadDefaultDrive = 0
Set-Location AD:
Set-ADServerSettings -ViewEntireForest:$true -PreferredServer $DomainController
- 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.”
- 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
Restore-ADObject
- 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.