blob: ad23d45a0dbc1334e78fdd6f0d258aa9459ab9ec (
plain)
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
|
param
(
[string]$ParentDomainName = "contoso.com",
[string]$ChildDomainName = "dev",
[string]$SafeModePassword = "P4ssw0rd1234!",
[string]$Username = "Administrator",
[string]$Password = "packer"
)
$scriptName = $MyInvocation.MyCommand.Name
$logFile = "C:\Logs\${scriptName}_log.txt"
Start-Transcript -Path $logFile -Append
$p = ConvertTo-SecureString $Password -AsPlainText -Force
$c = New-Object System.Management.Automation.PSCredential("$ParentDomainName\$Username", $p)
Write-Host "[INFO] Setting Administrator password"
$computerName = $env:COMPUTERNAME
$adminPassword = $Password
$adminUser = [ADSI] "WinNT://$computerName/Administrator,User"
$adminUser.SetPassword($adminPassword)
Write-Host "[INFO] Installing AD-Domain-Services feature"
Install-WindowsFeature AD-Domain-Services -IncludeAllSubFeature -IncludeManagementTools
Write-Host "[INFO] Importing ADDSDeployment module"
Import-Module ADDSDeployment
try {
Write-Host "[INFO] Installing New Child Domain in Existing Forest"
Install-ADDSDomain `
-InstallDns `
-ParentDomainName $ParentDomainName `
-NewDomainName $ChildDomainName `
-DomainType ChildDomain `
-DatabasePath "C:\Windows\NTDS" `
-LogPath "C:\Windows\NTDS" `
-SysvolPath "C:\Windows\SYSVOL" `
-NoRebootOnCompletion `
-Force `
-Credential $c `
-SafeModeAdministratorPassword (ConvertTo-SecureString -AsPlainText -Force "$SafeModePassword")
Write-Host "[INFO] Successfully added new child domain: $ChildDomainName"
} catch {
Write-Host "[ERR] Failed to add new child domain: $ChildDomainName"
Write-Host $_.Exception.Message
}
Stop-Transcript
|