Advertisement
Guest User

LABServerConfig.ps1

a guest
Aug 31st, 2016
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [cmdletbinding()]param()
  2.  
  3. Set-location "C:\dsctemp"
  4.    
  5.  
  6. [DSCLocalConfigurationManager()]
  7. configuration LCMConfig
  8. {
  9.     Node localhost
  10.     {
  11.         settings
  12.         {
  13.             ActionAfterReboot = 'ContinueConfiguration'
  14.             ConfigurationMode = 'ApplyOnly'
  15.             RebootNodeIfNeeded = $true
  16.         }
  17.     }
  18. }
  19. LCMConfig
  20. Set-DscLocalConfigurationManager -ComputerName localhost -Force -Verbose -path .\LCMConfig
  21.  
  22.  
  23. configuration DSCLabServer
  24. {
  25.  
  26.    
  27.     Import-DscResource –ModuleName PSDesiredStateConfiguration
  28.     Import-DSCResource -ModuleName xPSDesiredStateConfiguration
  29.     Import-DSCResource -ModuleName xCertificate
  30.     Import-DSCResource -ModuleName xActiveDirectory
  31.     Import-DSCResource -ModuleName xAdcsDeployment
  32.     Import-DscResource -ModuleName xComputerManagement
  33.     Import-DSCResource -ModuleName xDhcpServer
  34.     Import-DSCResource -ModuleName xNetworking
  35.  
  36.     Node $AllNodes.Where{$_.Role -eq "PrimaryServer"}.Nodename
  37.     {
  38.        
  39.         User Administrator
  40.         {
  41.             UserName = "Administrator"
  42.             Password = $Node.DomainCred
  43.             Ensure = 'Present'
  44.         }
  45.         WindowsFeature DSCServiceFeature
  46.         {
  47.             Ensure = 'Present'
  48.             Name   = 'DSC-Service'            
  49.         }
  50.         WindowsFeature ServerGuiMgmtInfra
  51.         {
  52.             Ensure = 'Present'
  53.             Name   = 'Server-Gui-Mgmt-Infra'            
  54.         }
  55.         WindowsFeature ServerGuiShell
  56.         {
  57.             Ensure = 'Present'
  58.             Name   = 'Server-Gui-Shell'
  59.             IncludeAllSubFeature = $true            
  60.         }      
  61.         $IPIndex = 0
  62.         foreach($IP in $Node.IPs){
  63.             $IPIndex++
  64.             xIPAddress "NewIPAddress$IPindex"
  65.             {
  66.                 IPAddress      = $IP.IPAddress
  67.                 InterfaceAlias = $IP.InterfaceAlias
  68.                 SubnetMask     = $IP.SubnetMask
  69.                 AddressFamily  = $IP.AddressFamily
  70.                
  71.             }
  72.             xDefaultGatewayAddress "DefaultGatewayAddress$IPIndex"
  73.             {
  74.                 Address = $IP.DefaultGateway
  75.                 AddressFamily  = $IP.AddressFamily
  76.                 InterfaceAlias = $IP.InterfaceAlias
  77.  
  78.             }
  79.             xDnsServerAddress "DnsServerAddress$IPIndex"
  80.             {
  81.                 Address        = $IP.DNSServer
  82.                 InterfaceAlias = $IP.InterfaceAlias
  83.                 AddressFamily  = $IP.AddressFamily
  84.             }            
  85.         }
  86.         xComputer NewComputerName
  87.         {
  88.             Name = $Node.ComputerName
  89.             DependsOn = "[xIPAddress]NewIPAddress$IPindex"
  90.         }
  91.         File ADDatabasePath          
  92.         {            
  93.             DestinationPath = $Node.ADDatabasePath            
  94.             Type = 'Directory'            
  95.             Ensure = 'Present'            
  96.         }
  97.         File ADLogPath
  98.         {            
  99.             DestinationPath = $Node.ADLogPath          
  100.             Type = 'Directory'            
  101.             Ensure = 'Present'            
  102.         }
  103.         WindowsFeature ADDSInstall            
  104.         {            
  105.             Ensure = "Present"            
  106.             Name = "AD-Domain-Services"            
  107.         }            
  108.         WindowsFeature RSATRoleTools            
  109.         {            
  110.             Ensure = "Present"
  111.             Name = "RSAT-Role-Tools"
  112.             IncludeAllSubFeature = $true
  113.         }
  114.         xADDomain PromoteDC          
  115.         {            
  116.             DomainName = $Node.DomainName
  117.             DomainNetBIOSName= $Node.DomainNetBIOSName
  118.             DomainAdministratorCredential = $Node.DomainCred
  119.             SafemodeAdministratorPassword = $Node.SafemodeAdministratorPassword          
  120.             DatabasePath = $Node.ADDatabasePath            
  121.             LogPath = $Node.ADLogPath            
  122.             DependsOn = "[WindowsFeature]ADDSInstall","[File]ADDatabasePath","[File]ADLogPath","[xComputer]NewComputerName","[User]Administrator"
  123.         }
  124.         xDscWebService PSDSCPullServer
  125.         {
  126.             Ensure = 'Present'
  127.             EndpointName = 'PSDSCPullServer'
  128.             Port = 8080
  129.             PhysicalPath = "$env:SystemDrive\inetpub\PSDSCPullServer"
  130.             CertificateThumbPrint = 'AllowUnencryptedTraffic'
  131.             ModulePath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Modules"
  132.             ConfigurationPath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration"
  133.             State = 'Started'
  134.             DependsOn = '[WindowsFeature]DSCServiceFeature'                        
  135.         }
  136.         File RegistrationKeyFile
  137.         {
  138.             Ensure          = 'Present'
  139.             Type            = 'File'
  140.             DestinationPath = "$env:ProgramFiles\WindowsPowerShell\DscService\RegistrationKeys.txt"
  141.             Contents        = $Node.DSCRegistrationKey
  142.         }
  143.         WindowsFeature DHCP {
  144.             DependsOn = "[xComputer]NewComputerName"
  145.             Name = 'DHCP'
  146.             Ensure = 'PRESENT'
  147.             IncludeAllSubFeature = $true
  148.         }
  149.         xDhcpServerAuthorization LocalServerActivation
  150.         {
  151.             Ensure = 'Present'
  152.             DependsOn = '[xADDomain]PromoteDC','[WindowsFeature]DHCP'
  153.         }
  154.         xDhcpServerScope Scope
  155.         {
  156.             DependsOn = '[xDhcpServerAuthorization]LocalServerActivation'
  157.             Ensure = 'Present'
  158.             IPEndRange = $Node.DHCPIPEndRange
  159.             IPStartRange = $Node.DHCPIPStartRange
  160.             Name = $Node.DHCPName
  161.             SubnetMask = $Node.DHCPSubnetMask
  162.             LeaseDuration = $Node.DHCPLeaseDuration
  163.             State = $Node.DHCPState
  164.             AddressFamily = $Node.DHCPAddressFamily
  165.         }        
  166.         xDhcpServerOption Option
  167.         {
  168.             Ensure = 'Present'
  169.             ScopeID = $Node.DHCPScopeID
  170.             DnsDomain = $Node.DomainName
  171.             DnsServerIPAddress = $Node.DHCPDnsServerIPAddress
  172.             AddressFamily = $Node.DHCPAddressFamily
  173.             Router = $Node.DHCPRouter
  174.             DependsOn = '[xDhcpServerScope]Scope'
  175.         }
  176.         WindowsFeature ADCSCertAuthority
  177.         {
  178.                Ensure = 'Present'
  179.                Name = 'ADCS-Cert-Authority'
  180.         }        
  181.         xADCSCertificationAuthority ADCS
  182.         {
  183.             Ensure = 'Present'
  184.             Credential = $Node.DomainCred
  185.             CAType = 'EnterpriseRootCA'
  186.             DependsOn = '[WindowsFeature]ADCSCertAuthority','[xADDomain]PromoteDC'
  187.             CACommonName = "$($Node.DomainNetBIOSName) Root CA"
  188.             HashAlgorithmName = "SHA256"
  189.             KeyLength = 4096
  190.             ValidityPeriod = "Years"
  191.             ValidityPeriodUnits = 20
  192.  
  193.         }
  194.         WindowsFeature ADCSWebEnrollment
  195.         {
  196.             Ensure = 'Present'
  197.             Name = 'ADCS-Web-Enrollment'
  198.             DependsOn = '[WindowsFeature]ADCSCertAuthority'
  199.         }
  200.         xADCSWebEnrollment CertSrv
  201.         {
  202.             Ensure = 'Present'
  203.             IsSingleInstance = 'Yes'
  204.             Credential = $Node.DomainCred
  205.             DependsOn = '[WindowsFeature]ADCSWebEnrollment','[xADCSCertificationAuthority]ADCS'
  206.         }
  207.     }
  208. }
  209.  
  210. $password = "Test@123!" | ConvertTo-SecureString -asPlainText -Force
  211. $DomainCred = New-Object System.Management.Automation.PSCredential("ADATUM\administrator",$password)
  212. $SafemodeAdministratorPassword = New-Object System.Management.Automation.PSCredential("administrator",$password)
  213.  
  214. $ConfigData = 'a'
  215.  
  216. $ConfigData = @{            
  217.     AllNodes = @(            
  218.         @{            
  219.             Nodename = "localhost"
  220.             PSDscAllowDomainUser = $true
  221.             PSDscAllowPlainTextPassword = $true
  222.             ComputerName = 'LABDC01'
  223.             Role = "PrimaryServer"
  224.             DomainName = "adatum.com"
  225.             DomainNetBIOSName = "ADATUM"
  226.             ADDatabasePath = "C:\NTDS"
  227.             ADLogPath = "C:\NTDS\LOG"
  228.             DomainCred = $DomainCred
  229.             SafemodeAdministratorPassword = $SafemodeAdministratorPassword
  230.             IPs = @(
  231.                 @{            
  232.                     IPAddress = '192.168.0.2'
  233.                     SubnetMask = 24
  234.                     AddressFamily = 'IPv4'
  235.                     InterfaceAlias = 'Ethernet'
  236.                     DNSServer = '192.168.0.2'
  237.                     DefaultGateway = '192.168.0.1'
  238.                 }
  239.             )            
  240.             DHCPScopeID = '192.168.0.0'
  241.             DHCPIPStartRange = '192.168.0.3'
  242.             DHCPIPEndRange = '192.168.0.254'            
  243.             DHCPName = '192.168.0.0'
  244.             DHCPSubnetMask = '255.255.255.0'
  245.             DHCPLeaseDuration = '00:08:00'
  246.             DHCPState = 'Active'
  247.             DHCPAddressFamily = 'IPv4'
  248.             DHCPDnsServerIPAddress = '192.168.0.2'
  249.             DHCPRouter = '192.168.0.1'
  250.             RetryCount = 20              
  251.             RetryIntervalSec = 30
  252.             DSCRegistrationKey = "$([guid]::NewGuid())"          
  253.         }            
  254.     )            
  255. }
  256.  
  257. DSCLabServer -ConfigurationData $ConfigData
  258. Start-DscConfiguration -ComputerName localhost -Wait -Force -Verbose -path .\DSCLabServer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement