2

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.

warren
  • 18,369
  • 23
  • 84
  • 135
  • 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

1 Answers1

5

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 username@domain.com /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.

Chris S
  • 77,945
  • 11
  • 124
  • 216