Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PowerShell code for installing AD and running DC Promo via an Answer file for Win2K8R2 (for ASE and AD blog post)
$AccountName = 'my-admin'
$vmpwd = 'ReplaceWithAStrongPassword'
$SecurePassword = ConvertTo-SecureString $vmpwd -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($AccountName, $SecurePassword);
Import-Module ServerManager
Add-WindowsFeature GPMC, Backup-Features, Backup, Backup-Tools,DNS,WINS-Server -Verbose
Add-WindowsFeature AS-NET-Framework -Verbose
Add-WindowsFeature AD-Domain-Services, ADDS-Domain-Controller -Verbose
$Domain = 'acme.local'
$NetBiosDomainName = 'acme'
$ADSite = 'acme-site1'
<#
This entry specifies the forest functional level when a new domain is created in a new forest as follows:
0 = Windows 2000 Server
2 = Windows Server 2003
3 = Windows Server 2008
#>
$ForestLevel = 2
<#
This entry specifies the domain functional level. This entry is based on the levels that exist in the forest when a new domain is created in an existing forest. Value descriptions are as follows:
0 = Windows 2000 Server native mode
2 = Windows Server 2003
3 = Windows Server 2008
#>
$Domainlevel = 2
$DSSafeModePassword = $vmpwd
$DCPromoFile = @"
[DCINSTALL]
InstallDNS=yes
NewDomain=forest
NewDomainDNSName=$Domain
DomainNetBiosName=$NetBiosDomainName
SiteName=$ADSite
ReplicaorNewDomain=domain
ForestLevel=$ForestLevel
DomainLevel=$Domainlevel
ConfirmGC=Yes
SafeModeAdminPassword=$DSSafeModePassword
RebootonCompletion=Yes
"@
# Output config file to text file
$DCPromoFile | out-file c:\dcpromoanswerfile.txt -Force
# Run DCPromo with the correct config
& 'C:\Windows\System32\dcpromo.exe' /unattend:c:\dcpromoanswerfile.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment