DSC Lab Automation

This topic contains 15 replies, has 5 voices, and was last updated by Profile photo of Mariusz Serwin Mariusz Serwin 1 year, 11 months ago.

  • Author
    Posts
  • #23897
    Profile photo of H Man
    H Man
    Participant

    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")            
    
    
    
  • #23898
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    I don't see a WindowsFeature resource in your configuration to install the DHCP Server role. That might be the problem.

  • #23900
    Profile photo of H Man
    H Man
    Participant

    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?

  • #23901
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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.

  • #23902
    Profile photo of H Man
    H Man
    Participant

    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!

  • #23903
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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.

  • #23904
    Profile photo of H Man
    H Man
    Participant

    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

  • #23906
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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'

  • #23907
    Profile photo of H Man
    H Man
    Participant

    ok will do thanks again

  • #23909
    Profile photo of H Man
    H Man
    Participant

    If i wanted to also set this dc with a static iP where can I do that?

  • #23910
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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.

  • #23911
    Profile photo of H Man
    H Man
    Participant

    ok thanks

  • #23916
    Profile photo of H Man
    H Man
    Participant

    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")     
    
  • #23956
    Profile photo of Raymond Slieff
    Raymond Slieff
    Participant

    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.

    • #23976
      Profile photo of Dean Ellerby
      Dean Ellerby
      Participant

      you could put the DHCP stuff above the ADDSInstall

      And by [i]above[/i], that means within a dependency tree which would dictate it must happen first; placing it [i]physically[/i] above isn't enough.

  • #23999
    Profile photo of Mariusz Serwin
    Mariusz Serwin
    Participant

    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

You must be logged in to reply to this topic.