Setting Up a Domain Controller with PowerShell

Bradley Schacht is a Principal Program Manager on the Microsoft Fabric product team based in Saint Augustine, FL. Bradley is a former consultant, trainer, and has coauthored 6 SQL Server and Power BI books, most recently Learn Microsoft Fabric. As a member of the Microsoft Fabric product team, Bradley works directly with customers to solve some of their most complex data problems and helps shape the future of Microsoft Fabric. Bradley gives back to the community through speaking at events such as the SQLBits, Fabric Community Conference, PASS Community Data Summit, SQL Saturdays, Code Camps, and user groups across the country including locally at the Jacksonville SQL Server User Group (JSSUG). He is a contributor on SQLServerCentral.com and blogs on his personal site, BradleySchacht.com.




Note: This can also be done theough the GUI by accessing the Computer Settings > Select Change Settings in the Computer name, domain, and workgroup settings section. Step 3: Add Active Directory Features Since we are going to use this same virtual machine for everything (DC, database, SharePoint, etc.) we need to setup a domain controller before going any further. This could be done through the GUI, but again, PowerShell provides the ability to add the features and configure the domain forest in just a couple of lines of code.
Once the features have been added to the computer your screen should look like the following screenshot indicating a successful addition and no restart is required. You will also notice a note telling you that Windows Updates should be enabled if they aren't already. I tend to ignore that suggestion on my demo environments partially because my demo computers usually don't have internet access.
Step 3: Configure the Domain Forest Once the appropriate features have been added to your virtual machine it is time to set up the domain controller. Normally this would be done by running dcpromo.exe but as we have done thus far, I am going to turn to PowerShell. If you have ever performed these tasks using the GUI you will realize how much faster the PowerShell option is.


Step 4: Log In With Domain Credentials After the server reboots you will notice that the prompt is now asking you to log in with domain credentials. Log in and enjoy your new domain controller!
Some other cleanup steps you may want to do which I perform on all my demo computers.