Rename Computers with PowerShell

less than 1 minute read

Some documentation refers to the Rename-Computer cmdlet, but according to this post, providing an invalid computer name could cause unexpected results. Since local and remote computers can already be renamed using WMI and netdom.exe, the cmdlet was removed. The MSDN documentation indicates the Rename method will not work on domain members, but I have tested this technique on Windows 7 and XP systems in a domain.

Get-WmiObject Win32_ComputerSystem -ComputerName OLDNAME -Authentication 6 |
ForEach-Object {$_.Rename("NEWNAME","PASSWORD","USERNAME")}

The Get-Credential cmdlet can be used to mask the password.

$credential = Get-Credential
Get-WmiObject Win32_ComputerSystem -ComputerName OLDNAME -Authentication 6 |
ForEach-Object {$_.Rename("NEWNAME",$credential.GetNetworkCredential().Password,$credential.Username)}

Remember to reboot the computer for the changes to take effect.

Get-WmiObject Win32_OperatingSystem -ComputerName OLDNAME |
ForEach-Object {$_.Win32Shutdown(6)}