Advertisement
Guest User

Untitled

a guest
Feb 18th, 2017
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. configuration CreateADPDC
  2. {
  3.    # Set parameters for deployment
  4.    param
  5.    (
  6.         # Gets the Domain name from .json script parameters
  7.         [Parameter(Mandatory = $true)]
  8.         [String]$DomainName,
  9.  
  10.         # Gets the DomainNetBIOS name from .json script parameters
  11.         [Parameter(Mandatory = $true)]
  12.         [string]$DomainNetbiosName,
  13.  
  14.         # Gets the adminstrator credentials from .json script parameters
  15.         [Parameter(Mandatory = $true)]
  16.         #[System.Management.Automation.PSObject]$Admincreds,
  17.         [System.Management.Automation.PSCredential]$Admincreds,
  18.  
  19.         # Gets the backupadminstrator credentials from .json script parameters
  20.         [Parameter(Mandatory = $true)]
  21.         [System.Management.Automation.PSCredential]$BackupadminCreds,
  22.  
  23.         # Gets the monitoradminstrator credentials from .json script parameters
  24.         [Parameter(Mandatory = $true)]
  25.         [System.Management.Automation.PSCredential]$MonitoradminCreds,
  26.  
  27.         # Retry count value, used for execute respons on AD deployment
  28.         [Int]$RetryCount=20,
  29.         [Int]$RetryIntervalSec=30
  30.     )
  31.    
  32.     # Import Powershell DSC modules
  33.     Import-DscResource -ModuleName xActiveDirectory, xDisk, xNetworking, xPendingReboot, cDisk
  34.  
  35.     # AD OU path, where the OU should be placed
  36.     $lines = $DomainName.Split(".")
  37.     foreach ($line in $lines)
  38.     {
  39.         $path += "dc=$line,"
  40.     }
  41.     $DomainPath = $path.TrimEnd(",")
  42.  
  43.     #Create DomainCreds
  44.     $DomainCreds = New-Object System.Management.Automation.PSCredential ("${DomainName}\$($Admincreds.UserName)", $Admincreds.Password)
  45.  
  46.     Node localhost
  47.     {
  48.         LocalConfigurationManager            
  49.         {            
  50.             ActionAfterReboot = 'ContinueConfiguration'            
  51.             ConfigurationMode = 'ApplyOnly'            
  52.             RebootNodeIfNeeded = $true            
  53.         }
  54.  
  55. #----------------------------------------------------------------
  56. ####################....Windows Feature(s)....####################
  57. #----------------------------------------------------------------  
  58.  
  59.         # Install DNS feature
  60.         WindowsFeature DNS
  61.         {
  62.             Ensure = "Present"
  63.             Name = "DNS"
  64.         }
  65.  
  66.         #Install the IIS Role
  67.         WindowsFeature IIS
  68.         {
  69.             Ensure = “Present”
  70.             Name = “Web-Server”
  71.         }
  72.  
  73.         # Install ADDS
  74.         WindowsFeature ADDSInstall
  75.         {
  76.             Ensure = "Present"
  77.             Name = "AD-Domain-Services"
  78.         }  
  79.  
  80.         # Optional GUI tools
  81.         WindowsFeature ADDSTools            
  82.         {            
  83.             Ensure = "Present"            
  84.             Name = "RSAT-ADDS"            
  85.         }  
  86.  
  87.         # Install RSAT-ADDS-Tools
  88.         WindowsFeature RSAT-ADDS-Tools
  89.         {
  90.             Ensure = "Present"
  91.             Name = "RSAT-ADDS-Tools"
  92.         }
  93.  
  94.         # Install RSAT-AD-AdminCenter
  95.         WindowsFeature RSAT-AD-AdminCenter
  96.         {
  97.             Ensure = "Present"
  98.             Name = "RSAT-AD-AdminCenter"
  99.         }
  100.        
  101.         # Install RSAT-DNS-Tools
  102.         WindowsFeature DNSTools
  103.         {
  104.             Name = "RSAT-DNS-Server"
  105.         }
  106.  
  107. #----------------------------------------------------------------
  108. ####################....PRE....####################
  109. #----------------------------------------------------------------
  110.  
  111.         # Configure DC nic with best practice settings
  112.         $firstActiveAdapter = Get-NetAdapter -InterfaceDescription "Microsoft Hyper-V Network Adapter*" | Sort-Object -Property ifIndex | Select-Object -First 1
  113.         xDnsServerAddress DnsServerAddress
  114.         {
  115.             Address        = '127.0.0.1'
  116.             InterfaceAlias = $firstActiveAdapter.InterfaceAlias
  117.             AddressFamily  = 'IPv4'
  118.             DependsOn = "[WindowsFeature]DNS"
  119.         }
  120.  
  121.         # Wait for datadisk
  122.         xWaitforDisk Disk2
  123.         {
  124.              DiskNumber = 2
  125.              RetryIntervalSec =$RetryIntervalSec
  126.              RetryCount = $RetryCount
  127.         }
  128.  
  129.         # Give disk nr2 letter F:\
  130.         cDiskNoRestart ADDataDisk
  131.         {
  132.             DiskNumber = 2
  133.             DriveLetter = "F"
  134.         }
  135.  
  136.         # No slash at end of folder paths
  137.         xADDomain FirstDS
  138.         {
  139.             DomainName = $DomainName
  140.             DomainNetbiosName = $DomainNetbiosName
  141.             DomainAdministratorCredential = $DomainCreds
  142.             SafemodeAdministratorPassword = $DomainCreds
  143.             DatabasePath = "F:\NTDS"
  144.             LogPath = "F:\NTDS"
  145.             SysvolPath = "F:\SYSVOL"
  146.             DependsOn = "[WindowsFeature]ADDSInstall","[xDnsServerAddress]DnsServerAddress","[cDiskNoRestart]ADDataDisk"
  147.         }
  148.  
  149.         # Wait for AD to deploy
  150.         xWaitForADDomain DscForestWait
  151.         {
  152.             DomainName = $DomainName
  153.             DomainUserCredential = $DomainCreds
  154.             RetryCount = $RetryCount
  155.             RetryIntervalSec = $RetryIntervalSec
  156.             DependsOn = "[xADDomain]FirstDS"
  157.         }
  158.                      
  159. #----------------------------------------------------------------
  160. ####################....OU....####################
  161. #----------------------------------------------------------------
  162.                
  163.         # Create OU named after NetBIOS name, saved on domain root level
  164.         xADOrganizationalUnit DefaultOU
  165.         {
  166.            Name = $DomainNetbiosName
  167.            Path = $DomainPath
  168.            ProtectedFromAccidentalDeletion = $true
  169.            Description = "Default managed OU"
  170.            Ensure = 'Present'
  171.            DependsOn = "[xWaitForADDomain]DscForestWait"
  172.         }            
  173.                        
  174.         # Create Groups Sub OU
  175.         xADOrganizationalUnit GroupsSubOU
  176.         {
  177.            Name = 'Groups'
  178.            Path = "ou=$DomainNetbiosName," + $DomainPath
  179.            ProtectedFromAccidentalDeletion = $true
  180.            Description = "Groups SubOU"
  181.            Ensure = 'Present'
  182.            DependsOn = "[xWaitForADDomain]DscForestWait"
  183.         }
  184.  
  185.         # Create Users Sub OU
  186.         xADOrganizationalUnit UsersSubOU
  187.         {
  188.            Name = 'Users'
  189.            Path = "ou=$DomainNetbiosName," + $DomainPath
  190.            ProtectedFromAccidentalDeletion = $true
  191.            Description = "Users SubOU"
  192.            Ensure = 'Present'
  193.            DependsOn = "[xWaitForADDomain]DscForestWait"
  194.         }
  195.  
  196.         # Create RDS Sub OU
  197.         xADOrganizationalUnit RDSSubOU
  198.         {
  199.            Name = 'RDS'
  200.            Path = "ou=$DomainNetbiosName," + $DomainPath
  201.            ProtectedFromAccidentalDeletion = $true
  202.            Description = "RDS SubOU"
  203.            Ensure = 'Present'
  204.            DependsOn = "[xWaitForADDomain]DscForestWait"
  205.         }
  206.  
  207. #----------------------------------------------------------------
  208. ####################....USERS --> GROUP(S)....####################
  209. #----------------------------------------------------------------
  210.  
  211.         # adminuser with Password never exipre
  212.         xADUser adminuser
  213.         {
  214.            DomainName = $DomainName
  215.            DomainAdministratorCredential = $domainCreds
  216.            UserName = $adminCreds.UserName
  217.            Password = $adminCreds
  218.            PasswordNeverExpires = $true
  219.            Ensure = "Present"
  220.            Description = "Account used for operator based actions from Dustin Operations"
  221.            DependsOn = "[xWaitForADDomain]DscForestWait"
  222.         }
  223.  
  224.         # adminuser with Password never exipre
  225.         xADUser backupadminuser
  226.         {
  227.            DomainName = $DomainName
  228.            DomainAdministratorCredential = $domainCreds
  229.            UserName = $BackupadminCreds.UserName
  230.            Password = $BackupadminCreds
  231.            PasswordNeverExpires = $true
  232.            Ensure = "Present"
  233.            Description = "Backupadmin User"
  234.            DependsOn = "[xWaitForADDomain]DscForestWait"
  235.         }
  236.  
  237.         # adminuser with Password never exipre
  238.         xADUser monitoradminuser
  239.         {
  240.            DomainName = $DomainName
  241.            DomainAdministratorCredential = $domainCreds
  242.            UserName = $MonitoradminCreds.UserName
  243.            Password = $MonitoradminCreds
  244.            PasswordNeverExpires = $true
  245.            Ensure = "Present"
  246.            Description = "Account used for automated actions from Dustin Operations"
  247.            DependsOn = "[xWaitForADDomain]DscForestWait"
  248.         }
  249.  
  250.         # Create Active Directory group
  251.         xADGroup ADGroup
  252.         {
  253.            GroupName = "G-SQL-Admin"
  254.            GroupScope = "Global"
  255.            Category = "Security"
  256.            Description = "Used for sysadmin level - SQL instanse"
  257.            Ensure = 'Present'
  258.            Path = "ou=Groups,ou=$DomainNetbiosName," + $DomainPath
  259.            Members = $adminCreds.UserName, $BackupadminCreds.UserName
  260.            DependsOn = "[xADUser]adminuser", "[xADUser]backupadminuser", "[xADUser]monitoradminuser", "[xADOrganizationalUnit]GroupsSubOU"
  261.         }
  262.  
  263.         # Add users Domain Admins group
  264.         xADGroup DomainAdmins
  265.         {
  266.            GroupName = "Domain Admins"
  267.            Ensure = 'Present'
  268.            Path = "cn=Users," + $DomainPath
  269.            MembersToInclude = $BackupadminCreds.UserName, $MonitoradminCreds.UserName
  270.            DependsOn = "[xADUser]adminuser", "[xADUser]backupadminuser", "[xADUser]monitoradminuser"
  271.         }
  272.  
  273. #----------------------------------------------------------------
  274. ####################....MISC....####################
  275. #----------------------------------------------------------------
  276.  
  277.         # Enable Active Directory Recycle Bin
  278.         xADRecycleBin RecycleBin
  279.         {
  280.            EnterpriseAdministratorCredential = $DomainCreds
  281.            ForestFQDN = $DomainName
  282.            DependsOn = "[xWaitForADDomain]DscForestWait"
  283.         }
  284.  
  285.         # Pending reboot after AD deploy
  286.         xPendingReboot Reboot1
  287.         {
  288.             Name = "RebootServer"
  289.             DependsOn = "[xWaitForADDomain]DscForestWait"
  290.         }
  291.    }
  292. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement