PowerShell: Rename a Computer
Need to change a machine's hostname - as part of a naming convention cleanup, imaging process, or asset management update? This one-liner renames it directly from the terminal.
Prerequisites:
- Privileges: Run as Administrator
- Module: Built-in, no import needed
Quick Command:
Rename-Computer -NewName "NewPCName" -Restart
This requires a restart to take effect, and -Restart triggers it immediately once the rename completes. Save any open work first, and don't run this on a machine you're actively using without planning for the reboot.
📦
Want all of them at once?
Get every free one-liner from this blog in a single downloadable bundle organized by category, each with full comment-based help. No more copy-pasting one at a time.
Get every free one-liner from this blog in a single downloadable bundle organized by category, each with full comment-based help. No more copy-pasting one at a time.
How It Works:
- Rename-Computer changes the machine's hostname - the same value returned by Win32_ComputerSystem's Name property, covered in the hostname article earlier.
- -NewName "NewPCName" sets the new hostname - replace this with whatever name you actually want.
- -Restart forces an immediate restart after the rename, since the new name doesn't fully take effect (especially for network visibility) until the system reboots. Without this parameter, the rename is staged but won't apply until the next manual restart.