官术网_书友最值得收藏!

Renaming and domain joining

Every server that you build will need a hostname, and most likely will need to be joined to your domain. We are all likely 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.

Getting ready

We have just finished turning on a new Windows Server 2019 machine. Immediately following the mini-setup wizard in order to get logged into Windows, let's use PowerShell to set our hostname and join the system to our domain.

How to do it…

Follow these steps to rename and domain join this new server with PowerShell:

  1. Open a PowerShell session as an administrator.
  2. In order to rename our new server WEB02, input the following command. Using the -Restart flag will ensure that our server reboots following the name change:

    Rename-Computer -NewName WEB02 -Restart

    You will receive the following output:

    Figure 3.20 – The Rename-Computer command

  3. That's it for renaming! Now that our WEB2 server has rebooted, open PowerShell again and use the Add-Computer command in order to join it to our domain:

    Add-Computer -DomainName ad.cookbook.packt.com -Credential cookbook\Administrator -Restart

  4. Since we specified an account to use as credentials when joining the domain, we are prompted to supply the password. As soon as you enter the password, the server will be joined to the domain and will immediately restart to complete the process:

    Figure 3.21 – A credential request prompt

  5. If you wanted to rename your computer and join it to the domain in a single step instead of rebooting in between, you can do that with the following command:

    Add-Computer -NewName web02 -DomainName ad.cookbook.packt.com -Credential cookbook\Administrator

  6. Following the reboot, in system properties, you will be able to see that our server is now appropriately named and domain joined:

Figure 3.22 – System properties showing the renamed and domain joined server

How it works…

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.

See also

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:

主站蜘蛛池模板: 沾化县| 正镶白旗| 正宁县| 道孚县| 内丘县| 山阴县| 启东市| 宁武县| 三都| 丹寨县| 沈丘县| 东乌珠穆沁旗| 南靖县| 齐齐哈尔市| 土默特右旗| 海丰县| 新郑市| 房山区| 友谊县| 文水县| 大宁县| 济南市| 金塔县| 绩溪县| 伊通| 广东省| 汾阳市| 双流县| 汕尾市| 遵义县| 读书| 镇平县| 兰西县| 五华县| 正阳县| 齐河县| 舞阳县| 正镶白旗| 和平区| 阜新市| 乐亭县|