application-workloads/active-directory/active-directory-new-domain-ha-2-dc-zones/DSC/CreateADPDC.ps1 (94 lines of code) (raw):

configuration CreateADPDC { param ( [Parameter(Mandatory)] [String]$DomainName, [Parameter(Mandatory)] [System.Management.Automation.PSCredential]$Admincreds, [Int]$RetryCount=20, [Int]$RetryIntervalSec=30 ) Import-DscResource -ModuleName xActiveDirectory, xStorage, xNetworking, PSDesiredStateConfiguration, xPendingReboot [System.Management.Automation.PSCredential ]$DomainCreds = New-Object System.Management.Automation.PSCredential ("${DomainName}\$($Admincreds.UserName)", $Admincreds.Password) $Interface=Get-NetAdapter|Where Name -Like "Ethernet*"|Select-Object -First 1 $InterfaceAlias=$($Interface.Name) Node localhost { LocalConfigurationManager { RebootNodeIfNeeded = $true } WindowsFeature DNS { Ensure = "Present" Name = "DNS" } Script EnableDNSDiags { SetScript = { Set-DnsServerDiagnostics -All $true Write-Verbose -Verbose "Enabling DNS client diagnostics" } GetScript = { @{} } TestScript = { $false } DependsOn = "[WindowsFeature]DNS" } WindowsFeature DnsTools { Ensure = "Present" Name = "RSAT-DNS-Server" DependsOn = "[WindowsFeature]DNS" } xDnsServerAddress DnsServerAddress { Address = '127.0.0.1' InterfaceAlias = $InterfaceAlias AddressFamily = 'IPv4' DependsOn = "[WindowsFeature]DNS" } xWaitforDisk Disk2 { DiskNumber = 2 RetryIntervalSec =$RetryIntervalSec RetryCount = $RetryCount } xDisk ADDataDisk { DiskNumber = 2 DriveLetter = "F" DependsOn = "[xWaitForDisk]Disk2" } WindowsFeature ADDSInstall { Ensure = "Present" Name = "AD-Domain-Services" DependsOn="[WindowsFeature]DNS" } WindowsFeature ADDSTools { Ensure = "Present" Name = "RSAT-ADDS-Tools" DependsOn = "[WindowsFeature]ADDSInstall" } WindowsFeature ADAdminCenter { Ensure = "Present" Name = "RSAT-AD-AdminCenter" DependsOn = "[WindowsFeature]ADDSTools" } xADDomain FirstDS { DomainName = $DomainName DomainAdministratorCredential = $DomainCreds SafemodeAdministratorPassword = $DomainCreds DatabasePath = "F:\NTDS" LogPath = "F:\NTDS" SysvolPath = "F:\SYSVOL" DependsOn = @("[WindowsFeature]ADDSInstall", "[xDisk]ADDataDisk") } xPendingReboot RebootAfterPromotion{ Name = "RebootAfterPromotion" DependsOn = "[xADDomain]FirstDS" } } }