Saturday, March 5, 2016

Powershell Rocks, Rejoin computers in domain without restart

I received below error many many times when logging to some critical server and I am stuck. (I am very sure you also must have received this error many times)
The trust relationship between this workstation and the primary domain failed.
Due to this error I cannot login into server with my domain credentials. In old days I had to disjoin this server from domain, reboot and rejoin again. This was big headache for Mission Critical servers. If you like using Powershell for system management it is very easy to rejoin computer account to domain without restarting server. You must have at least Powershell version 3 to use this command which is by default there in windows 2012 server version and windows 8. 

Video how to use Test-ComputerSecureChannel
It is obvious that you can use your domain accounts means you have to use your local administrator account to login, and open powershell as administrator.
Once powershell is fired up you have to just run below command to rejoin computer into domain without restart.

Test-ComputerSecureChannel -Repair -Credential (Get-Credential)

It prompts for username password, It should be domain and should have AD rights. 
It will simply repair broken computer account password on your computer. and will give message True. Once this is done and you can logoff and test logging with your Domain account, This trick has saved me many times when there was restriction on rebooting Server, even plenty of time I used it on my own desktop, so I dont have reboot and I can work undisturbed (I found I can no longer access file servers and other things).
there is old trick for old OS you can use Netdom command (I used to use it on Windows 2008 r2 and lower OS, you can find this netdom 2008 os series by default, for older you can download it from its CD/DVD)
netdom resetpwd /Server:DC /UserD:DomainAdmin /PasswordD:Password
In next blog I found one more command to rejoing computer into domain without reboot.

Resolved: The trust relationship between this workstation and the primary domain failed

Post a Comment