The Active Directory Recycle Bin was introduced in Windows 2008 R2. In this version the Recycle Bin must be enabled, and the only way to undelete a user account is to use the Restore-ADObject command, with pretty arcane parameters.
I wanted to use Well Known GUIDs to refer to the the location of the deleted objects container, and that of the User’s container which I chose as the default location for the restored user object. The Well-Known GUIDs allow for a constant to be used for these containers. For example, The WKD for DeletedObjects is 18E2EA80684F11D2B9AA00C04F79F805. I had hoped to be able to used this directly for the identity for the Restore-ADObject command, but quickly discovered that this was not accepted. Getting the DN from the WKD turns out to be a pain in the neck, so I modified some code to get this information for any domain in the forest. How do you get the information for another domain? The easiest answer, for all of the PowerShell AD commands is to use the -Server switch with the DNSDomain name, instead of a true server name.
The script will let you select the domain to search, and the destination for the restored user object. PowerShell 3 is required, as I use Out-Gridview to create a list of the user(s) to restore.
Finally, I hard coded in a test variable in line 14. Change it to $bTest = $False if you are ready to take the plunge. The script, Undelete-User.ps1, should make restoring users a little easier.