Home > database >  How do I change the hostname of a Windows PC with batch or powershell
How do I change the hostname of a Windows PC with batch or powershell

Time:10-29

I want to change the hostname of a computer from Batch (a.k.a. Command Prompt) or Powershell.

Initially I started research into using the wmic command. But running wmic /? on Windows 10 21H1 indicates it is now deprecated.

enter image description here

Then I looked at Get-WmiObject. But when I run man Get-WmiObject in PowerShell, the description indicates it has been "superseded" by Get-CimInstance.

enter image description here

Using the old Get-WmiObject command you could change your own computer's hostname with (Get-WmiObject Win32_ComputerSystem).Rename("New-Hostname").

What is a non-deprecated way to change your own Windows computer's hostname using Batch or PowerShell?

CodePudding user response:

Thanks to @Theo for the tip.

The PowerShell command Rename-Computer

Rename-Computer "new-hostname"

Admin privileges and a computer restart are required.

The command warns you if the length of the hostname is longer than 15 characters.

CodePudding user response:

The bat file command...

NETDOM RENAMECOMPUTER "%ComputerName%" /Newname:"NewNameGoesHere" /FORCE

  • Related