There are a dozen ways for you to rename a computer on a domain. The PowerShell script, below, is a fun way to take care of a few misnamed machines efficiently. If you wanted, you could even embed it within your AD management tools to make the whole process a one-click affair.
It starts by prompting for your domain credentials. It then enters a While loop. I really enjoy the simplicity of using While ($true) as it creates a forever loop.
You will then be prompted for the old/current computer name, new computer name, and if you would like to restart the machine. Once the machine is renamed, it will automatically repeat the process. The old/current computer does have to be turned on and on the domain. Of course, you do need permission to rename the computer.
When it comes to renaming computers, your methods now equal a baker’s dozen. As everyone knows – that is the best type of dozen. If you have any questions or suggestions, leave a comment below!
$Credential = Get-Credential -Message User: username@DOMAIN or Domain\Username While ($true){ write-host "" $OldComputerName = Read-Host "What is the old computer name?" $NewComputerName = Read-Host "What is the new computer name?" $Restart = Read-Host "Restart the computer? Y for yes or N for no." if ($Restart -eq "Y"){ Rename-Computer -ComputerName $OldComputerName -NewName $NewComputerName -Restart -Force -DomainCredential $Credential -verbose } if ($Restart -ne "Y"){ Rename-Computer -ComputerName $OldComputerName -NewName $NewComputerName -Force -DomainCredential $Credential -verbose } }$Credential = Get-Credential -Message User: username@DOMAIN or Domain\Username While ($true){ write-host "" $OldComputerName = Read-Host "What is the old computer name?" $NewComputerName = Read-Host "What is the new computer name?" $Restart = Read-Host "Restart the computer? Y for yes or N for no." if ($Restart -eq "Y"){ Rename-Computer -ComputerName $OldComputerName -NewName $NewComputerName -Restart -Force -DomainCredential $Credential -verbose } if ($Restart -ne "Y"){ Rename-Computer -ComputerName $OldComputerName -NewName $NewComputerName -Force -DomainCredential $Credential -verbose } }