Create a New Domain with PowerShell

By | 2021-11-11

If you’re standing up a new domain, this bit of PowerShell will get you there without the need to run through the wizard.

All you should need to modify are the variables in the first four lines of the script. Where this comes in handy is when you might be deploying a lab environment, or perhaps building a new production domain.

# Modify these variables to fit your needs

$DomainNameFQDN="MyDomain.Local"
$DomainNetBios="MyDomain"
$DCLocalUser = "AdminUserName"
$ImagePW="MyStrongPassword"

# Shouldn't need to mod anything below this line.

$DCLocalPWord = ConvertTo-SecureString -String $ImagePW -AsPlainText -Force
Add-WindowsFeature -Name "ad-domain-services" -IncludeAllSubFeature -IncludeManagementTools
Add-WindowsFeature -Name "dns" -IncludeAllSubFeature -IncludeManagementTools
Add-WindowsFeature -Name "gpmc" -IncludeAllSubFeature -IncludeManagementTools 

$domainname = $DomainNameFQDN
$netbiosName = $DomainNetBios
Import-Module ADDSDeployment

Install-ADDSForest -CreateDnsDelegation:$false `
-DatabasePath "C:\Windows\NTDS" `
-DomainMode "WinThreshold" `
-DomainName $domainname `
-DomainNetbiosName $netbiosName `
-SafeModeAdministratorPassword $DCLocalPWord `
-ForestMode "WinThreshold" `
-InstallDns:$true `
-LogPath "C:\Windows\NTDS" `
-NoRebootOnCompletion:$false `
-SysvolPath "C:\Windows\SYSVOL" `
-Force:$true

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.