Skip to content

Windows — Rename Computer via PowerShell

Rename-Computer is the PowerShell way to change a hostname. It works locally and against remote machines without needing to touch System Properties.

Run PowerShell as Administrator.


Check the Current Hostname

$env:COMPUTERNAME

Rename and Restart Immediately

Rename-Computer -NewName "new-hostname" -Restart

The machine renames itself and reboots. The new name is active after the restart.


Rename Without Immediate Restart

Rename-Computer -NewName "new-hostname"

The change is staged but not applied until the next reboot. Restart when convenient:

Restart-Computer

Rename a Remote Computer

Rename-Computer -ComputerName "old-hostname" -NewName "new-hostname" -LocalCredential domain\admin -Restart

This does not require PowerShell remoting to be enabled on the target.


Domain-Joined Machines

Renaming a domain-joined machine requires domain credentials:

Rename-Computer -NewName "new-hostname" -DomainCredential domain\admin -Restart

You will be prompted for the password if you omit it from the credential object.

AD propagation

After the reboot, allow a few minutes for the name change to replicate through Active Directory before using the new name for remote connections.


Naming Rules

  • Allowed characters: letters (a–z, A–Z), digits (0–9), hyphens (-)
  • No spaces, no dots
  • Maximum 63 characters (DNS limit)
  • NetBIOS limit: 15 characters — names longer than 15 are truncated in older Windows networking and AD

Verify After Reboot

$env:COMPUTERNAME

Or from another machine:

(Get-ADComputer "new-hostname").Name