application-workloads/visualstudio/tfs-basic-domain/DSC/CreateDC.ps1 (69 lines of code) (raw):

configuration CreateDC { param ( [Parameter(Mandatory)] [String]$DomainName, [Parameter(Mandatory)] [System.Management.Automation.PSCredential]$Admincreds, [Int]$RetryCount = 20, [Int]$RetryIntervalSec = 30 ) Import-DscResource -ModuleName xActiveDirectory, xNetworking [System.Management.Automation.PSCredential] $DomainCreds = New-Object System.Management.Automation.PSCredential ("${DomainName}\$($Admincreds.UserName)", $Admincreds.Password) $Interface = Get-NetAdapter | Where-Object 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" } 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]ADDSInstall" } xADDomain FirstDS { DomainName = $DomainName DomainAdministratorCredential = $DomainCreds SafemodeAdministratorPassword = $DomainCreds DependsOn = @("[WindowsFeature]ADDSInstall") } } }