To rename a Windows computer with PowerShell, open PowerShell as an administrator and run Rename-Computer -NewName with the new name. Add -Restart, because the new name only takes effect after a restart:
Rename-Computer -NewName 'SALES-NY-014' -Restart
It works the same in PowerShell 7 and Windows PowerShell 5.1. I didn’t rename my own PC for this article. Every example below either uses -WhatIf or only reads settings, and I replaced my real computer name with DESKTOP-4T7K2QX.
Check the current computer name
"Computer name: $env:COMPUTERNAME"
"DNS host name: $([System.Net.Dns]::GetHostName())"
Output:
Computer name: DESKTOP-4T7K2QX
DNS host name: DESKTOP-4T7K2QX
Write down the old name before you change it. You’ll need it to find the computer in your inventory or in Active Directory.
There are several ways to read the name, compared in getting the computer name.
Preview the rename with -WhatIf
-WhatIf shows what Rename-Computer would do, without changing anything:
Rename-Computer -NewName 'SALES-NY-014' -WhatIf
Output:
What if: Performing the operation "Rename-Computer" on target "DESKTOP-4T7K2QX".

When you run it for real, Windows warns that the change takes effect after a restart. Add -Restart to reboot right away, or restart later.
Computer name rules
| Rule | Example that fails |
|---|---|
| 15 characters or fewer | ACCOUNTING-LAPTOP-07 |
| Letters, numbers and hyphens only | HR_PC01, SALES.NY |
| Not all numbers | 20260928 |
| Doesn’t start or end with a hyphen | DEV- |
The Rename-Computer help mentions 63 characters, which is the DNS limit. Windows itself allows only 15, as Microsoft’s naming conventions article explains. I check names with a small function before renaming:
function Test-ComputerName {
param([Parameter(Mandatory)] [string]$Name)
if ($Name.Length -gt 15) { return 'too long (15 characters max)' }
if ($Name -notmatch '^[A-Za-z0-9-]+$') { return 'only letters, numbers and hyphens' }
if ($Name -match '^\d+$') { return "can't be all numbers" }
if ($Name -match '^-|-$') { return "can't start or end with a hyphen" }
'OK'
}
foreach ($name in 'SALES-NY-014', 'ACCOUNTING-LAPTOP-07', 'HR_PC01', '20260928', 'DEV-') {
'{0,-21} {1}' -f $name, (Test-ComputerName -Name $name)
}
Output:
SALES-NY-014 OK
ACCOUNTING-LAPTOP-07 too long (15 characters max)
HR_PC01 only letters, numbers and hyphens
20260928 can't be all numbers
DEV- can't start or end with a hyphen

Rename a domain-joined computer
For a computer in an Active Directory domain, pass an account that’s allowed to rename computers in the domain. You’ll be asked for its password:
Rename-Computer -NewName 'SALES-NY-014' -DomainCredential CONTOSO\it-admin -Restart
This renames the computer account in Active Directory too, so the PC keeps its trust with the domain.
Rename a remote computer
Use -ComputerName for the current name of the remote PC. According to the Rename-Computer documentation, this doesn’t need PowerShell remoting to be set up:
Rename-Computer -ComputerName 'DESKTOP-8H2K1LM' -NewName 'SALES-NY-014' `
-DomainCredential CONTOSO\it-admin -Force -Restart
-Force skips the confirmation prompt. Only use it when you’ve checked the names, because a wrong rename means another restart.