Repository navigation
Expand file tree
/
Copy pathNewDomainController.ps1
More file actions
107 lines (89 loc) · 3.54 KB
/
Copy pathNewDomainController.ps1
File metadata and controls
107 lines (89 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#Jonathan Bourbonnais - 2019
#This DSC recipe add a domain controller to an existing forest (it do not create a new forest)
#This script is provided as-is and is configured in push mode
#For further direction on DSC, refer to : https://docs.microsoft.com/en-us/powershell/scripting/dsc/resources/resources?view=powershell-6
#Declare the hostname for the new DC
$server = Read-Host -Prompt "Enter the hostname for your new DC"
#NewDomainController is a function you will be able to call
Configuration NewDomainController
{
#DECLARE PARAMETER
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCredential]
$DomainAdministratorCredential
)
#Importe DSC ressources
#You may need to install them manualy
Import-DscResource -ModuleName xActiveDirectory
Import-DscResource -ModuleName xNetworking
Import-DscResource -ModuleName NetworkingDsc
node $server
{
#Disable DHCP on the network adapter
NetIPInterface 'DisableDHCP'
{
InterfaceAlias = 'Ethernet_lan'
AddressFamily = 'IPV4'
Dhcp = 'Disabled'
}
#Configure static IP adress
IPAddress 'NewIPV4Address'
{
IPAddress = '10.40.38.110'
InterfaceAlias = 'Ethernet_lan'
AddressFamily = 'IPV4'
DependsOn = '[NetIPInterface]DisableDHCP'
}
#Install ADDS
WindowsFeature 'InstallADDomainServicesFeature'
{
Ensure = 'Present'
Name = 'AD-Domain-Services'
}
#Install PowerShell RSAT
WindowsFeature 'RSATADPowerShell'
{
Ensure = 'Present'
Name = 'RSAT-AD-PowerShell'
DependsOn = '[WindowsFeature]InstallADDomainServicesFeature'
}
#Install RSAT GUI
WindowsFeature 'RSATADDSTools'
{
Ensure = 'Present'
Name = 'RSAT-ADDS'
DependsOn = '[WindowsFeature]RSATADPowershell'
}
#Check if the domain exist
xWaitForADDomain 'WaitForestAvailability'
{
DomainName = 'contoso.com'
DomainUserCredential = $DomainAdministratorCredential
RetryCount = 10
RetryIntervalSec = 120
DependsOn = '[WindowsFeature]RSATADDSTools'
}
#Configure ADDS
xADDomainController 'DomainControllerAllProperties'
{
DomainName = 'contoso.com'
DomainAdministratorCredential = $DomainAdministratorCredential
SafemodeAdministratorPassword = $DomainAdministratorCredential
DatabasePath = 'C:\Windows\NTDS'
LogPath = 'C:\Windows\Logs'
SysvolPath = 'C:\Windows\SYSVOL'
#SiteName = ''
#isGlobalCatalog = $true
DependsOn = '[xWaitForADDomain]WaitForestAvailability'
}
}
}
#Start the DSC Configuration
Start-DscConfiguration -Path C:\Path\To\DSC\Config\File\NewDomainController\ -ComputerName "YOUR-PC-NAME" -Verbose -Debug -Wait -Force
#Run these command if you need to install a DSC module manualy
#Find-Module -Name NetworkingDsc -Repository PSGallery | Install-Module
#Find-Module -Name xActiveDirectory -Repository PSGallery | Install-Module
#Find-Module -Name xNetworking -Repository PSGallery | Install-Module