How to install a Domain Controller using Powershell

   With Windows Vista and newer editions of Windows Server/Desktop a powerful component was added to help System Administrators automatize operations that normally would take a long period of time. With Powershell you can interact with the whole Operating System and perform even more actions than using the GUI. If you are a Microsoft System Administrator than Powershell is the perfect tool for you. In this article we will discover some of it’s features and we will install and configure a Domain Controller that runs ADDS and DNS service.
  Note that I will be using Windows Powershell v2.0 to install all features and promote the Server  to a Domain Controller because Windows Server 2008 R2 is shipped with this version. In newer versions of Powershell this operation is much easier to acomplish because Microsoft released Cmdlets that enables you to complete some operations much faster.
Before we can actually start installing our Domain Controller we have to change it’s default Computer Name with the one that we desire. I want to rename my Server to Win2008DC, this is how the Powershell code would look like:


$newName = “Win2008DC”
$computerName = Get-WmiObject Win32_ComputerSystem 


shutdown /r /t 0
Get-WmiObject Win32_ComputerSystem
Get-WmiObject Win32_ComputerSystem
   New let’s set a static IP configuration for our new Domain Controller. You will need to execute the following commands one by one or create a Powershell script (.ps1) and execute it:


$wmi = Get-WmiObject win32_networkadapterconfiguration -filter “ipenabled = ‘true'”
$wmi.EnableStatic(“”, “”)


$dnslist = “”, “”


  Type ipconfig /all to view the network configuration after the script has finished its process:
ipconfig command
   Once the Computer Name and the network configuration have been completed, it’s time to install the Active Directory Domain Services. We need to import the server manager module by typing Import-Module ServerManager. If you want to view the loaded modules, you’ll need to use the Get-Module command. All available modules can be viewed with Get-Module -ListAvailable command:
Get-Module -ListAvailable
   You can view all available Windows Features by typing Get-WindowsFeature. This command offers an overview of all the features installed on your Windows Server. Let’s refine the search by looking only on installed features by typing Get-WindowsFeature | where {$_.Installed -eq “True”}. You should have no output since Windows comes shipped with no feature installed. Right now we’re interested in installing ADDS (Active Directory Domain Services) and DNS service for our Domain Controller.
If you don’t know what commands you can use within a module you can simply type Get-Command -module ServerManager:
Get-Command -module ServerManager
   Type Add-WindowsFeature Ad-Domain-Services to install the ADDS feature. You’ll need to wait a bit until the installation is finished:
Add-WindowsFeature Ad-Domain-Services
   Once the installation is completed, we can promote the Server to a Domain Controller. We will accomplish this by using dcpromo command with several parameters as follows:
dcpromo /unattend /InstallDNS:yes /DnsOnNetwork:yes /ReplicaOrNewDomain:Domain /NewDomain:Forest / /DomainNetbiosName:ppscu /databasePath:”C:\Windows\ntds” /logPath:”C:\Windows\ntds” /sysvolpath:”C:\Windows\Sysvol” /SafeModeAdminPassword:”1qaz@WSX” /forestLevel:4 /domainLevel:4 /rebootOnCompletion:yes
I’ll not explain all these parameters but, you can discover all of them and their detailed description in this link from Microsoft’s website.
Promote a Domain Controller using Powershell
   Once this operation is complete, the server will be restarted and finally, you’ll have a Domain Controller running ADDS and DNS services. The new forest and domain will be created and also the primary DNS zone. You can aggregate all these commands in a big Powershell script and deploy a server pretty fast.
   Hope you’ve understood the things written in this article, for any misunderstandings don’t hesitate to post a question. Wish you all the best and stay tuned for the following articles from IT training day.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s