I have been trying to use the Add-Computer Cmdlet to take and newly generated Windows 2019 and 2016 EC2 Instance, which starts with a randomly generated hostname, and set the hostname, and join it to the domain. So far, I have not been able to get this to work without having two steps and two reboots. I have to Rename-Computer, reboot, and Add-Computer and reboot.
I have tried so many things, I have lost track, but here is one example:
Add-Computer -DomainName $domain -OUPath $ouPath -Credential $credential -NewName $($nameValue.Split(".")[0]) -Force –Options JoinWithNewName,AccountCreate -ErrorAction Stop -Restart\n
Does anyone have tested and proven method for changing the name of a Windows Server and Joining it to the domain with only one reboot? I have tried add-computer -newname, it doesn’t work.
I have done this many times manually, I just ignore the first reboot prompt. I assume your -Restart\n is intended to perform the same action? I am not familiar with that syntax. If that is not the case, what happens if you leave off the -Restart and simply try the second task, then reboot?
Yes, it did. The workaround was so complicated, that I decided to just go with the reboot. Eventually, change the standard and our AWS server just take the hostname AWS gives it. This raised another problem with the way we did service accounts, but that is another story.