Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I change the hostname of a Windows server using a script?

Doing this on a Linux server is very straightforward (change a couple file entries, and run the hostname command), but I don't know how, or even if it's possible, to change a hostname on Windows in an automated fashion.

Specifically I'm looking for a way to do this on Windows 2008 R2, but a generic approach would be great, too.

I found this technote for XP, but haven't tried it on a 2k8 machine - is it still valid?

The entire context is to be able to change a server's name post-deployment from a VMware template without using a Custom Specification.

share|improve this question
Why is is you don't want to automate VM creation but do want to automate system names? – Jim B Apr 27 '12 at 14:56
@Jim B - corporate restrictions on automatic system names – warren Apr 27 '12 at 16:13
I'd love to hear more about that. My usual problem is figuring out how to script in the corporate naming standard. This is the first case I've ever heard of where a corporate naming standard is explicitly forbidden. – Jim B Apr 27 '12 at 22:02
@Jim B - the corporate naming standard is not "forbidden" - it's enforced - for the host itself .. the VM name may or may not be the same as the corporate naming standard – warren Apr 28 '12 at 17:17
so why not have a scripted install uses the custom template (or IMHO use MDT and skip the templates alltogether) – Jim B Apr 30 '12 at 18:12
up vote 4 down vote accepted

The link you found is valid and the Best Practices way of configuring a Server Core install.

netdom renamecomputer localhost /NewName:FooBar

Works on remote machines too by changing localhost to something that allows Windows to resolve the remote computer. If a remote computer is specificed you'll need to supply credentials unless domain credentials or Windows Passthrough auth applies.

Specify creds with /UserO username /PasswordO password for local authentication
Use /UserD /PasswordD password for domain authentication.

NetDom is also the same utility used to scrip joining a computer to a domain, to manage DNS Alternate names (poorly conceived, don't use them), and a variety of other administrative tasks.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.