I am in the process of writing a script that will add a PC to a domain. I am using the following line to do this.
Add-Computer -ComputerName $env:COMPUTERNAME -NewName $serial -DomainName $domain -Credential $credential
The problem is the computer was previously on the domain and So it is telling me It is unable to rename the computer because the account already exists.
I believe that the script is adding the computer to the domain and then renaming it.
I understand the easiest solution is to delete the PC from AD unfortunately that is not an option.
Is there a way to write this so that I can rename the PC and add it to the domain without restarting in between the 2.