Search Tools Links Login

Create a New Domain with PowerShell


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

About this post

Posted: 2021-11-11
By: dwirch
Viewed: 501 times

Categories

Tip

Active Directory

Powershell

Windows

SysAdmin Tools

PowerShell Code Cache

Attachments

No attachments for this post


Loading Comments ...

Comments

AnonymousCoward posted this comment on 2021-11-12:

Thank you for putting this up.

You must be logged in to make a comment.