Join a machine to a domain and rename using PowerShell

Q. How can I join a machine to a domain and rename it using PowerShell?

A. PowerShell version 3 introduces a -NewName parameter for Add-Computer which enables a machine to join and domain and have a new name set with a single command. This removes having to rename the machine using:

(Get-WmiObject win32_computersystem).Rename("$server")

The new command would therefore be:

Add-Computer -Credential cred -DomainName savilltech.net -NewName server;Restart-Computer -force

Note I also use Restart-Computer to complete the rename and domain join operation.

Each week, John Savill answers all of your toughest tech questions about the worlds of Windows Server, Azure, and beyond. Read his past IT advice here, and email your questions to [email protected].

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish