Summary: Scripting Games Beginner Event 6: Dr. Scripto needs to join core servers to the domain and rename them. Microsoft Scripting Guy, Ed Wilson, is here. Today is the revealing of the final event for the 2013 Scripting Games. I hope you have learned tons from this year’s games and had fun too. Remember that you need to go to www.powershell.org to submit your event. Good luck!
The Core Configurator
Dr. Scripto has just one final challenge for you: to get out alive!
No, wait…that was when Bond was over for tea and crumpets last week.
Ah, here we go…
Dr. Scripto is deploying a bunch of new virtual machines on a Server Core installation of Windows Server 2012. The virtual machines already have the operating system installed, and the local Administrator password is set to P@ssw0rd. The Doctor has created a text file named C:Mac.txt, which contains the MAC addresses of each virtual machine’s active network adapter (one address per line in the file). The virtual machines are using DHCP to get an IP address. There is a DHCP server on the network named DHCP1, and it has a single DHCP scope named 10.0.0.0. The virtual machines’ current computer names are not known, and they do not yet belong to the domain.
You need to write a Windows PowerShell script that joins the virtual machines to the domain and gives them a new computer name. By using the information in Mac.txt, you must perform the following for each computer with a Server Core installation:
- Query the Server Core installation’s current dynamic IP address from the DHCP server.
- Join each Server Core installation to the Company.local domain. Use the domain credential Admin, with the password P@ssw0rd, to join the computer to the domain. At the same time, rename the computer. The first computer should be named SERVER1, the second SERVER2, and so forth. Allow the computer to restart.
You should minimize the number of “Are you sure?” prompts that are shown while your script runs. The computers should be added to the domain’s default container for new machine objects.
It’s fine if you do this for one computer at a time, but when your script finishes running, all of the computers must be properly provisioned.
You can safely assume that SERVER1, SERVER2, and so on do not already exist in the domain. You do not need to parameterize your script (values like SERVERx), and the Mac.txt file name and other values can be hardcoded.
I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at email@example.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson, Microsoft Scripting Guy