Basically, there are different ways to rejoin computers in the domain. You have to be physically in front of it to make changes as in general when you simply rename the computer name, it will start giving an issue
“The trust relationship between this workstation and the primary domain failed to fix remotely“.
I couldn’t get the solution in one place, so I thought to share my solution in the blog after googling different alternatives for a couple of days.
First, you can simply rename computer name from Powershell
Rename-computer –computername “old_computer_name” –newname “newcomputername” –domaincredential domain\user –force –restart
Note: Strongly recommends to have a local administrator account on the machine which you are renaming. You will need it later. Else, you will be screwed up.
In some cases, after this people recommend to Reset Account of the computer from Active Directory. But, I found it doesn’t help.
So, as a next step, we have to enable WINRM on the remote machine to start PS Session from your local machine.
You have to use PSExec Tool to enable WINRM. You can download the tool from an official site of Microsoft.
PsExec.exe \\newcomputername -u newcomputername\administrator -s winrm.cmd quickconfig –q
Also, add a new computer name as a trusted host.
winrm s winrm/config/client '@{TrustedHosts="Newcomputername"}'
Here, you can also use a third-party application such as Remote Execution Enabler for Powershell.
Once you complete this, you can establish a PS session with the local admin password of the remote machine.
Enter-PSSession -Computer “newcomputername” -Credential “newcomputername\ADMINISTRATOR”
Reset remote machine to establish new trust relationship
Reset-ComputerMachinePassword -Server "DomainControllerofyoursite" -Credential domain\domainadminaccount
That’s all. Feel free to drop a comment if you need any support or more information on it.