Setting Up Active Directory with PowerShell

What

This article provides a clear, concise guide on setting up Active Directory (AD) and adding a second domain controller using PowerShell commands on Windows Server.

Why

Automating the installation of Active Directory and deploying additional domain controllers via PowerShell ensures faster, consistent, and reliable setups. It enhances domain availability and redundancy without manual configuration.

How

Step 1: Install AD DS Role on the First Server

Install-WindowsFeature AD-Domain-Services -IncludeManagementTools

Step 2: Promote the First Server to a Domain Controller

Install-ADDSForest `
 -DomainName "example.local" `
 -DomainNetbiosName "EXAMPLE" `
 -SafeModeAdministratorPassword (ConvertTo-SecureString "P@ssw0rd!" -AsPlainText -Force) `
 -InstallDNS:$true `
 -Force

Step 3: Restart the First Server

Restart-Computer

Step 4: Verify the First Domain Controller

Get-ADDomain
Get-ADDomainController
Get-Service DNS

Step 5: Install AD DS Role on the Second Server

Install-WindowsFeature AD-Domain-Services -IncludeManagementTools

Step 6: Promote the Second Server as an Additional Domain Controller

Install-ADDSDomainController `
 -DomainName "example.local" `
 -Credential (Get-Credential) `
 -SafeModeAdministratorPassword (ConvertTo-SecureString "P@ssw0rd!" -AsPlainText -Force) `
 -InstallDNS:$true `
 -Force

Step 7: Restart the Second Server

Restart-Computer

Step 8: Verify Both Domain Controllers

Get-ADDomainController -Filter *

Conclusion

By following these steps, you can automate the deployment of a primary and secondary domain controller using PowerShell. This approach ensures a resilient and efficient Active Directory environment, supporting best practices for enterprise infrastructure.

Copied title and URL