-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy path2-Build-Active-Directory.ps1
51 lines (44 loc) · 1.83 KB
/
2-Build-Active-Directory.ps1
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
#--------------------------------------------------------------------------
#- Created by: David Rodriguez -
#- Blog: www.sysadmintutorials.com -
#- Twitter: @systutorials -
#- Youtube: https://www.youtube.com/user/sysadmintutorials -
#--------------------------------------------------------------------------
#-------------
#- Variables - -
#-------------
# Active Directory Variables
$domainname = 'vlab.local'
#------------
#- Settings -
#------------
# Install Active Directory Services
Try{
Add-WindowsFeature AD-Domain-Services -ErrorAction Stop
Install-WindowsFeature RSAT-ADDS -ErrorAction Stop
Write-Host "Active Directory Domain Services installed successfully" -ForegroundColor Green
}
Catch{
Write-Warning -Message $("Failed to install Active Directory Domain Services. Error: "+ $_.Exception.Message)
Break;
}
# Configure Active Directory
Try{
Install-ADDSForest -DomainName $domainname -InstallDNS -ErrorAction Stop -NoRebootOnCompletion
Write-Host "Active Directory Domain Services have been configured successfully" -ForegroundColor Green
}
Catch{
Write-Warning -Message $("Failed to configure Active Directory Domain Services. Error: "+ $_.Exception.Message)
Break;
}
# Reboot Computer to apply settings
Write-Host "Save all your work, computer rebooting in 30 seconds"
Sleep 30
Try{
Restart-Computer -ComputerName $env:computername -ErrorAction Stop
Write-Host "Rebooting Now!!" -ForegroundColor Green
}
Catch{
Write-Warning -Message $("Failed to restart computer $($env:computername). Error: "+ $_.Exception.Message)
Break;
}