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:
- 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:
$env:ADPS_LoadDefaultDrive = 0
Set-ADServerSettings -ViewEntireForest:$true -PreferredServer $DomainController
- Verify the availability of the AD Recycle Bin by running the following command:
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:
- Confirm that the user has been restored by running the following command, replacing “RestoredUser” with the actual name of the user:
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.