Hey everyone! I'm working on a PowerShell script to automate the process of adding devices to our domain, and I want the renaming of the device and joining the domain to happen at the same time. Ideally, I don't want to worry about whether a computer object with the same name already exists; I want it to overwrite or adopt that existing object instead. I've tried using the command below but ran into an error. Can anyone suggest a way to achieve this without needing to restart the computer twice? Here's the command I used:
Add-Computer -DomainName "My-Domain.local" -NewName "New-Computer" -Credential (Get-Credential) -Force -Restart
Error message: The computer "Desktop-15645" successfully joined the new domain "My-Domain.local," but could not be renamed to "New-Computer."
3 Answers
Actually, you don't necessarily have to delete the existing object. You could adjust the security permissions to allow your user account to reset the computer account's password while joining. For example, using `Reset-ADComputer -Identity computername -Confirm:$false` might help. If that doesn’t grant you authority, make sure you have the right permissions to join the domain with that existing name.
I understand the concern, but isn't there another command that could bypass this issue entirely? I've manually joined computers with names that already exist before, so it seems like there must be a way around it.
Looks like the issue arises because a computer object called "New-Computer" already exists in the domain, so it can't change the name of the one you're adding. Your options are to either delete the existing object (if it’s not in use) or choose a different name that isn't already in the domain.
Related Questions
Can't Load PhpMyadmin On After Server Update
Redirect www to non-www in Apache Conf
How To Check If Your SSL Cert Is SHA 1
Windows TrackPad Gestures