Every server that you build will need a hostname, and most likely will need to be joined to your domain. We are all familiar with doing these things with the mouse using system properties, but have you ever thought of using a command interface to do these tasks quickly? Let's work together to discover how PowerShell can once again help make these necessary tasks more efficient.
We have just finished turning on a new Windows Server 2016 machine. Immediately following the mini-setup wizard in order to get logged into Windows, let's now use PowerShell to set our hostname and join the system to our domain.
Follow these steps to rename and domain join this new server with PowerShell:
WEB2
, input the following command. Using the -Restart
flag will ensure that our server reboots following the name change:Rename-Computer -NewName WEB2 -Restart
Add-Computer
command in order to join it to our domain:Add-Computer -DomainName MYDOMAIN.LOCAL -Credential
MYDOMAIN.LOCALAdministrator -Restart
Through a couple of quick PowerShell cmdlets, we can rename computers and join them to our domain. In fact, these functions are even possible without ever logging into the console of the server. There are parameters that can be added to these cmdlets that allow you to run them remotely. For example, you could run the PowerShell commands from a local desktop computer, specifying that you want to run them against the remote server's IP address or name. By performing the functions this way, you never even have to log into the server itself in order to name and join it. See the links in the following section for additional information on these parameters.
Take a look at the following links for even more detailed information about the Rename-Computer
and Add-Computer
cmdlets that we used in this recipe:
13.59.123.182