Search
StarWind is a hyperconverged (HCI) vendor with focus on Enterprise ROBO, SMB & Edge

Creating a Domain on Windows Server 2016 via PowerShell

  • October 29, 2019
  • 10 min read
IT and Virtualization Consultant. Dmitriy is specializing in Microsoft technologies, with a focus on storage, networking, and IT infrastructure architecture.
IT and Virtualization Consultant. Dmitriy is specializing in Microsoft technologies, with a focus on storage, networking, and IT infrastructure architecture.

INTRODUCTION

Creating of Windows domain has always been a rock on which admins split. There are ones who will vouch for GUI. The others are more prone to PowerShell use. What do I think? Well, PowerShell is a flexible and universal tool, unlike GUI. So, no wonder this article is dedicated to creating and configuring a domain on Windows Server 2016 via PowerShell exclusively. I want to establish whether it will be helpful in the automation of this whole process.

PREPARING TO BEGIN

Now, since creating and configuring a domain controller (DC) is not something that will pass by your infrastructure, in order to avoid disrupting the working environment I am going to use a virtual machine (VM) inside of Hyper-V host running on Windows Server 2016 [Version 10.0.14393]. In turn, I will perform a domain verification via PowerShell as well, but from a test VM.

As you’ve probably guessed by now, for this test, I am going to use two VMs with the same configurations on Windows Server 2016:

  • 2 x Intel(R) Xeon(R) CPU E5-2609 0 @ 2.40GHz;
  • 1 x 4 GB RAM;
  • 1 x 100 GB HDD;
  • 1 x 10 Gbps LAN.

They’ll communicate with each other via the Hyper-V Private switch. You can find out how to create the latter here.

The environment scheme of my domain under the name “Test.com”:

The environment scheme of my domain under the name “Test.com”

In correspondence to my needs, in this case, creating and configuring a domain is basically installing Active Directory (AD), DNS and DHCP. These are the three primary services necessary to create any domain controller. I will depict precisely all of the configuration stages, performed with the use of PowerShell.

I’ll do the following:

  1. Installing and configuring AD and DNS;
  2. Installing and configuring DHCP;
  3. Check the status of the services on a domain client;
  4. Conclusions.

INSTALLATION AND CONFIGURATION OF AD AND DNS

First of all, I couldn’t do everything without using GUI, no matter how much I would want to. The first rocks on the way were logging in and starting the PowerShell. After logging in, start the Run utility. You’ll need to type Win+R, then PowerShell, and then click OK ( I marked all-important moments here and further with red):

Installation and configuration of AD and DNS

Now, the first thing to do with a machine that has a fresh OS on it is renaming it according to this environment scheme (much like client VM). After renaming and before start configuring, restart the VM:

Restart the VM

After restarting it, log in once again and check the host name:

Check the host name

Find the name of the network adapter:

 Find the name of the network adapter

At the next step, assign a new IP address for it, subnet mask, and default gateway. Since the test network is not supposed to reach the other systems, the default gateway address (172.16.0.1) is present purely nominally.

Subnet mask, and default gateway

As I am working here on creating and configuring a single domain controller, enter the loopback interface address (127.0.0.1) as the primary DNS server address. Leave the secondary DNS server address empty:

DNS server addres

Well, now it’s time for installing the services! Check the status of the services that weren’t installed yet but are available:

Check the status of the services

Install AD:

Install AD

Create a new domain forest:
Create a new domain forest

After the installation is complete, restart the VM.

After the installation is complete, restart the VM

Be attentive: this time, you’ll see domain entry as a default account! That means AD is already active.

AD is already active

Log in with a domain account, start the PowerShell, and continue. Check the status of the primary services necessary for AD.

Check the status of the primary services necessary for AD

Furthermore, check the AD Web service event log for mistakes.

Administrator Windows PowerShell

Check the AD service event log for mistakes.

Administrator Windows PowerShell

Make sure there no mistakes listed in the event logs and move further. Check the status of domain and forest:

Check the status of domain and forest

The next step is the installation and configuration of the DHCP service.

INSTALLATION AND CONFIGURATION OF DHCP

Install DHCP service:.

Check the status of domain and forest

Add the address pool for automatic allocation, at range 172.16.1.1 / 22 – 172.16.1.254 /22. Set the DHCP lease time and the gateway address. Restart the DHCP service.

Add the address pool for automatic allocation

Empty spaces between commands are to divide the lines for better understanding. They have no additional purpose, please, note this!

Add permission to manage DHCP.

Add permission to manage DHCP

Add DHCP record in the domain:

Add DHCP record in the domain

Stop the DHCP configuration in the server registry.

Stop the DHCP configuration

Apply the dynamic updates for clients:

Administrator Windows PowerShell

Congratulations, the configuration is finished now!

PERFORM THE SERVICES HEALTH CHECK ON THE DOMAIN CLIENT

Start the client VM (Test-VM), log in, and if the first thing you see is the network connection request, it means that the VM already connected to DHCP automatically.

Start the client VM (Test-VM

Start the PowerShell, check the current network configuration. Make sure that the client gets the correct DHCP network settings.

Start the PowerShell

Rename the VM.

 

Admanistrator Windows PowerShell

Add the client to the domain. At this stage, you’ll see the GUI pop-up window.

Add the client to the domain

Restart the client.

Restart the client

Log in, start the PowerShell, check network settings once more to make sure that the client has been added to the domain.

Log in, start the PowerShell

Check the DNS on the client.

Check the DNS on the client

CONCLUSIONS

I just tested the possibility of creating and configuring a domain on Windows Server 2016 via PowerShell. This task is generally possible. There are variations of using GUI during the configuration, but it’s a predictable issue since I didn’t use the Core version of Windows Server. However, it won’t stand in the way of partial automation of this process, something not possible with using the GUI. I hope you can make use of this material!

Found Dmitriy’s article helpful? Looking for a reliable, high-performance, and cost-effective shared storage solution for your production cluster?
Dmytro Malynka
Dmytro Malynka StarWind Virtual SAN Product Manager
We’ve got you covered! StarWind Virtual SAN (VSAN) is specifically designed to provide highly-available shared storage for Hyper-V, vSphere, and KVM clusters. With StarWind VSAN, simplicity is key: utilize the local disks of your hypervisor hosts and create shared HA storage for your VMs. Interested in learning more? Book a short StarWind VSAN demo now and see it in action!