Skip to content

Instantly share code, notes, and snippets.

@nivleshc
Last active September 8, 2016 07:26
Show Gist options
  • Save nivleshc/1106ff6a8333f8faec02cedec4c17506 to your computer and use it in GitHub Desktop.
Save nivleshc/1106ff6a8333f8faec02cedec4c17506 to your computer and use it in GitHub Desktop.
DSC to create a new Active Directory Forest
Configuration CreateNewADForest {
param
#v1.4
(
[Parameter(Mandatory)]
[String]$DomainName,
[Parameter(Mandatory)]
[System.Management.Automation.PSCredential]$AdminCreds,
[Parameter(Mandatory)]
[System.Management.Automation.PSCredential]$SafeModeAdminCreds,
[Parameter(Mandatory)]
[System.Management.Automation.PSCredential]$myFirstUserCreds,
[Int]$RetryCount=20,
[Int]$RetryIntervalSec=30
)
Import-DscResource -ModuleName xActiveDirectory, xNetworking, xPendingReboot
[System.Management.Automation.PSCredential ]$DomainCreds = New-Object System.Management.Automation.PSCredential ("${DomainName}\$($Admincreds.UserName)", $Admincreds.Password)
Node localhost
{
LocalConfigurationManager
{
ActionAfterReboot = 'ContinueConfiguration'
ConfigurationMode = 'ApplyOnly'
RebootNodeIfNeeded = $true
}
WindowsFeature DNS
{
Ensure = "Present"
Name = "DNS"
}
xDnsServerAddress DnsServerAddress
{
Address = '127.0.0.1'
InterfaceAlias = 'Ethernet'
AddressFamily = 'IPv4'
DependsOn = "[WindowsFeature]DNS"
}
WindowsFeature RSAT
{
Ensure = "Present"
Name = "RSAT"
}
WindowsFeature ADDSInstall
{
Ensure = "Present"
Name = "AD-Domain-Services"
}
xADDomain FirstDC
{
DomainName = $DomainName
DomainAdministratorCredential = $DomainCreds
SafemodeAdministratorPassword = $DomainCreds
DatabasePath = "C:\NTDS"
LogPath = "C:\NTDS"
SysvolPath = "C:\SYSVOL"
DependsOn = "[WindowsFeature]ADDSInstall","[xDnsServerAddress]DnsServerAddress"
}
xWaitForADDomain DscForestWait
{
DomainName = $DomainName
DomainUserCredential = $DomainCreds
RetryCount = $RetryCount
RetryIntervalSec = $RetryIntervalSec
DependsOn = "[xADDomain]FirstDC"
}
xADUser FirstUser
{
DomainName = $DomainName
DomainAdministratorCredential = $DomainCreds
UserName = $myFirstUserCreds.Username
Password = $myFirstUserCreds
Ensure = "Present"
DependsOn = "[xWaitForADDomain]DscForestWait"
}
xPendingReboot Reboot1
{
Name = "RebootServer"
DependsOn = "[xWaitForADDomain]DscForestWait"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment