Rename Windows Hostname from Command Line
-
If you need to change the hostname of a Windows box from the command line, the wmic tools make this a breeze. Use this pattern.
wmic computersystem where name="%COMPUTERNAME%" call Rename Name="NEW-HOSTNAME"
Using the where name="%COMPUTERNAME%" pattern lets you skip putting in the local machine name. The only piece you need to fill in is what your NEW-HOSTNAME should be.
Confirmed as working on ScreenConnect, too.
-
@scottalanmiller said in Rename Windows Hostname from Command Line:
Confirmed as working on ScreenConnect, too.
This is not something I even think about checking. Because if it runs non-interactive from a command prompt or powershell, it can run via screenconnect. Simple as that.
-
@scottalanmiller Why not use
Rename-Computer
instead from PowerShell? -
@black3dynamite said in Rename Windows Hostname from Command Line:
@scottalanmiller Why not use
Rename-Computer
instead from PowerShell?That's how I do it... less to type, less to remember, faster than using GUI.
-
Can I assume that all of the above will not affect domain membership and rename the computer in the domain correctly as well?
-
The PowerShell way will definitely not affect the domain membership. As for the wmic method, I have not tried that a single time to confirm.
-
@ingmarkoecher said in Rename Windows Hostname from Command Line:
Can I assume that all of the above will not affect domain membership and rename the computer in the domain correctly as well?
We used the wmic on a domain, and it worked fine.
-
@ingmarkoecher said in Rename Windows Hostname from Command Line:
Can I assume that all of the above will not affect domain membership and rename the computer in the domain correctly as well?
The
add-computer
cmdlet would be used for domain joining. -
The batch file I have for one client is this:
powershell Rename-Computer -NewName "COMPUTER_NAME" -DomainCredential DOMAIN\ADMINUser -Restart
Where
COMPUTER_NAME
to not exceed the 15 character limitETA:
I should add that this batch script start with installing Chocolatey package management tools, then the default applications,