Hi Guys
i’m looking to automate my lab builds, so I figured i would start off with the Domain Controller. I wanted to include a dhcp server as well all on the same VM.
Everything in my configuration file is working AD, DNS all configure fine , no errors , BUT no DHCP server either .
Here is my config file
configuration NewDomain
{
param
(
[Parameter(Mandatory)]
[pscredential]$safemodeAdministratorCred,
[Parameter(Mandatory)]
[pscredential]$domainCred
)
Import-DscResource -ModuleName xActiveDirectory , xDHCpServer
Node $AllNodes.Where{$_.Role -eq "Primary DC"}.Nodename
{
LocalConfigurationManager
{
ActionAfterReboot = 'ContinueConfiguration'
ConfigurationMode = 'ApplyOnly'
RebootNodeIfNeeded = $true
}
File ADFiles
{
DestinationPath = 'C:\NTDS'
Type = 'Directory'
Ensure = 'Present'
}
WindowsFeature ADDSInstall
{
Ensure = "Present"
Name = "AD-Domain-Services"
}
# Optional GUI tools
WindowsFeature ADDSTools
{
Ensure = "Present"
Name = "RSAT-ADDS"
}
# No slash at end of folder paths
xADDomain FirstDS
{
DomainName = $Node.DomainName
DomainAdministratorCredential = $domainCred
SafemodeAdministratorPassword = $safemodeAdministratorCred
DatabasePath = 'C:\NTDS'
LogPath = 'C:\NTDS'
DependsOn = "[WindowsFeature]ADDSInstall","[File]ADFiles"
}
xDhcpServerScope Scope
{
Ensure = 'Present'
IPEndRange = '192.168.1.254'
IPStartRange = '192.168.1.1'
Name = 'PowerShellScope'
SubnetMask = '255.255.255.0'
LeaseDuration = '00:08:00'
State = 'Active'
AddressFamily = 'IPv4'
DependsOn = "[WindowsFeature]ADDSInstall","[File]ADFiles" , "[WindowsFeature]ADDSTools" , "[xADDomain]FirstDS"
}
}
}
##----------------------------------------------------------------------##
# Configuration Data for AD---------------------------------------------##
$ConfigData = @{
AllNodes = @(
@{
Nodename = "10.22.0.145"
Role = "Primary DC"
DomainName = "hcorp.local"
RetryCount = 20
RetryIntervalSec = 30
PsDscAllowPlainTextPassword = $true
}
)
}
##----------------------------------------------------------------------##
#Run Config Create MOFs
NewDomain -ConfigurationData $ConfigData `
-safemodeAdministratorCred (Get-Credential -UserName '(Password Only)' `
-Message "New Domain Safe Mode Administrator Password") `
-domainCred (Get-Credential -UserName 'hcorp\administrator' `
-Message "New Domain Admin Credential")
system
April 2, 2015, 3:58am
2
I don’t see a WindowsFeature resource in your configuration to install the DHCP Server role. That might be the problem.
i was using the xDHCpServer resource… do i need to add the feature 1st? and use a depends on?
and i was then using
Import-DscResource -ModuleName xActiveDirectory , xDHCpServer
xDhcpServerScope Scope
{
Ensure = 'Present'
IPEndRange = '192.168.1.254'
IPStartRange = '192.168.1.1'
Name = 'PowerShellScope'
SubnetMask = '255.255.255.0'
LeaseDuration = '00:08:00'
State = 'Active'
AddressFamily = 'IPv4'
DependsOn = "[WindowsFeature]ADDSInstall","[File]ADFiles" , "[WindowsFeature]ADDSTools" , "[xADDomain]FirstDS"
}
is that not correct?
system
April 2, 2015, 4:21am
4
That’s important too, for setting up the scope. But you still need to install the DHCP server feature first, before you can configure it.
oh ok so just add this
WindowsFeature dhcp
{
Ensure = “Present”
Name = "DHCP
}
thats it? is the name correct? Should this have a depends on field?
as always Thank you!
system
April 2, 2015, 4:26am
6
Yep, looks correct (though you’re missing a closing quotation mark after DHCP).
The names that you use are the ones that show up when you run the Get-WindowsFeature command.
awesome thanks so much! 1 last ?
WindowsFeature dhcp
{
Ensure = “Present”
Name = “DHCP”
DependsOn = ???
}
do i need to add the DependsOn = for anything else to install 1st or is that ok
system
April 2, 2015, 4:33am
8
You don’t need to add a DependsOn to the WindowsFeature resource, but you should probably add a new entry to the xDhcpServerScope resource:
DependsOn = “[WindowsFeature]ADDSInstall”,“[File]ADFiles” , “[WindowsFeature]ADDSTools” , “[xADDomain]FirstDS”, ‘[WindowsFeature]dhcp’
If i wanted to also set this dc with a static iP where can I do that?
system
April 2, 2015, 4:48am
11
The xNetworking module has an xIPAddress resource (and the cNetworking fork has cIPAddress as well.) Off the top of my head, I’m not sure what changed in the community version, but it was probably a bug fix of some sort.
so i made the my changes and still no DHCP . it appears to be rebooting before it is installing dhcp. Isi t suppoes to continue after the reboot
here’s my new config file
configuration NewDomain
{
param
(
[Parameter(Mandatory)]
[pscredential]$safemodeAdministratorCred,
[Parameter(Mandatory)]
[pscredential]$domainCred
)
Import-DscResource -ModuleName xActiveDirectory , xDHCpServer, xnetworking
Node $AllNodes.Where{$_.Role -eq "Primary DC"}.Nodename
{
LocalConfigurationManager
{
ActionAfterReboot = 'ContinueConfiguration'
ConfigurationMode = 'ApplyOnly'
RebootNodeIfNeeded = $true
}
File ADFiles
{
DestinationPath = 'C:\NTDS'
Type = 'Directory'
Ensure = 'Present'
}
WindowsFeature ADDSInstall
{
Ensure = "Present"
Name = "AD-Domain-Services"
}
# Optional GUI tools
WindowsFeature ADDSTools
{
Ensure = "Present"
Name = "RSAT-ADDS"
}
WindowsFeature dhcp
{
Ensure = "Present"
Name = "dhcp"
}
xIPAddress SiteDCIP {
IPAddress = '192.168.1.110'
DefaultGateway = '255.255.255.0'
SubnetMask = '24'
AddressFamily = "IPv4"
InterfaceAlias = "Ethernet"
}
# No slash at end of folder paths
xADDomain FirstDS
{
DomainName = $Node.DomainName
DomainAdministratorCredential = $domainCred
SafemodeAdministratorPassword = $safemodeAdministratorCred
DatabasePath = 'C:\NTDS'
LogPath = 'C:\NTDS'
DependsOn = "[WindowsFeature]ADDSInstall","[File]ADFiles"
}
xDhcpServerScope Scope
{
Ensure = 'Present'
IPEndRange = '192.168.1.254'
IPStartRange = '192.168.1.1'
Name = 'PowerShellScope'
SubnetMask = '255.255.255.0'
LeaseDuration = '00:08:00'
State = 'Active'
AddressFamily = 'IPv4'
DependsOn = "[WindowsFeature]ADDSInstall","[File]ADFiles" , "[WindowsFeature]ADDSTools" , "[xADDomain]FirstDS" , "[WindowsFeature]dhcp"
}
}
}
##----------------------------------------------------------------------##
# Configuration Data for AD---------------------------------------------##
$ConfigData = @{
AllNodes = @(
@{
Nodename = "10.22.0.145"
Role = "Primary DC"
DomainName = "hcorp.local"
RetryCount = 20
RetryIntervalSec = 30
PsDscAllowPlainTextPassword = $true
}
)
}
##----------------------------------------------------------------------##
#Run Config Create MOFs
NewDomain -ConfigurationData $ConfigData `
-safemodeAdministratorCred (Get-Credential -UserName '(Password Only)' `
-Message "New Domain Safe Mode Administrator Password") `
-domainCred (Get-Credential -UserName 'hcorp\administrator' `
-Message "New Domain Admin Credential")
It should continue the script after a reboot. Alternatively since it does this in a linear fashion, you could put the DHCP stuff above the ADDSInstall, as the DHCP does not require a reboot of the system.
you could put the DHCP stuff above the ADDSInstall
And by above , that means within a dependency tree which would dictate it must happen first; placing it physically above isn’t enough.
Can you please check the logs from Event Viewer \applications and services logs\Microsoft \Windows\Desired State Configuration or use xDscDiagnostics Module .
Before you run the configuration make sure channels are enabled on the target node .
Update-xDscEventLogStatus -Channel Analytic -Status Enabled
Update-xDscEventLogStatus -Channel Debug -Status Enabled