How to install Active Directory using PowerShell

1 min read · Updated 16 October 2021

Did this guide help you? You can support me by subscribing to the channel, sharing it, disabling your ad blocker or making a donation. Thank you!

Third of four articles presenting different methods for installing Active Directory:
- Installing Microsoft Active Directory via the GUI (server 2012, 2012r2, 2016, 2019, 2022)
- Install Microsoft Active Directory via the dcpromo  command(server 2003, 2008, 2008r2, 2012, 2012r2, 2016, 2019, 2022)
- Install Microsoft Active Directory via PowerShell (server 2012, 2012r2, 2016, 2019, 2022)
- Installing Microsoft Active Directory via PowerShell DSC (server 2016, 2019, 2022)

PowerShell code - Active Directory installation

# Installing the role.
Add-WindowsFeature -Name AD-Domain-Services -IncludeManagementTools
# Configuring the role
$domaine = 'domaine.tld'
$DsrmPass = 'P@ssword'
Import-Module ADDSDeployment
$params = @{
CreateDnsDelegation = $false
# 2 ou Win2003, 3 ou Win2008, 4 ou Win2008R2, 5 ou Win2012, 6 ou Win2012R2,7 ou WinThreshold
DomainMode = 'Win2012r2'
DomainName = $domaine
DomainNetbiosName = $domaine.split('.')[0]
# 2 ou Win2003, 3 ou Win2008, 4 ou Win2008R2, 5 ou Win2012, 6 ou Win2012R2,7 ou WinThreshold
ForestMode = 'Win2012r2'
InstallDns = $true
DatabasePath = 'C:\Windows\NTDS'
LogPath = 'C:\Windows\NTDS'
SysvolPath = 'C:\Windows\SYSVOL'
NoRebootOnCompletion = $false
Force = $true
SafeModeAdministratorPassword = (ConvertTo-SecureString -AsPlainText -Force -String $DsrmPass)
}
Install-ADDSForest @params

Video : How to install Active Directory using PowerShell

Play

Related links