-
Notifications
You must be signed in to change notification settings - Fork 27
Description
Hey there. I am encountering an issue where the rename script is failing to successfully complete the rename properly. The error it throws is "The hostname is already taken by another device." However, no other device exists in AD. I've run into this issue in another environment as well, and was not able to identify what was causing it. From what I can tell, it appears that the DNS name is being updated, but not the computer object. So when it goes to update the computer object, it fails saying a device already exists with that name.
I was able to recreate the issue by running the following command:
PS C:\windows\system32> $name = Get-WmiObject -Class Win32_BIOS | Select-Object -Property SerialNumber
PS C:\windows\system32> $newname = $name.serialnumber
PS C:\windows\system32> Rename-Computer -ComputerName testrename -NewName $newname
Rename-Computer : Fail to rename computer 'TESTRENAME' to '8J6Q494' due to the following exception: The hostname is
already taken by another device.
At line:1 char:1
+ Rename-Computer -ComputerName testrename -NewName $newname
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (TESTRENAME:String) [Rename-Computer], InvalidOperationException
+ FullyQualifiedErrorId : FailToRenameComputer,Microsoft.PowerShell.Commands.RenameComputerCommand
Here are the logs from the RenameComputer script:
Transcript started, output file is C:\ProgramData\Microsoft\RenameComputer\RenameComputer.log
Device is joined to AD domain: REMOVED.local
Scheduled task unregistered.
Renaming computer to 8J6Q494
Rename-Computer : Fail to rename computer 'TESTRENAME' to '8J6Q494' due to the following exception: The hostname is
already taken by another device.
At C:\Temp\RenameComputer.ps1:161 char:5
+ Rename-Computer -NewName $newName -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (TESTRENAME:String) [Rename-Computer], InvalidOperationException
+ FullyQualifiedErrorId : FailToRenameComputer,Microsoft.PowerShell.Commands.RenameComputerCommand
Rename-Computer : Fail to rename computer 'TESTRENAME' to '8J6Q494' due to the following exception: The hostname is
already taken by another device.
At C:\Temp\RenameComputer.ps1:161 char:5
+ Rename-Computer -NewName $newName -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (TESTRENAME:String) [Rename-Computer], InvalidOperationException
+ FullyQualifiedErrorId : FailToRenameComputer,Microsoft.PowerShell.Commands.RenameComputerCommand
Initiating a restart in 10 minutes
**********************
Windows PowerShell transcript end
End time: 20250814224908
**********************
Here is a screenshot of the computer object in AD after the failed rename attempt. After rebooting the computer, the DNS name reverts back to the original computer name.
