-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall-ActiveDirectory.ps1
More file actions
33 lines (28 loc) · 1.29 KB
/
Install-ActiveDirectory.ps1
File metadata and controls
33 lines (28 loc) · 1.29 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
# Install-ActiveDirectory.ps1
# Installs AD DS and promotes server to Domain Controller
Install-WindowsFeature -Name AD-Domain-Services -IncludeManagementTools
Import-Module ADDSDeployment
$DomainName = Read-Host "Enter the domain name (example: school.local)"
Write-Host "Setting Local Administrator password..." -ForegroundColor Yellow
try {
$NewPassword = Read-Host "Enter a strong password for Local Administrator" -AsSecureString
$AdminAccount = [ADSI]"WinNT://./Administrator,User"
$AdminAccount.SetPassword([System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($NewPassword)))
$AdminAccount.SetInfo()
Write-Host "Local Administrator password updated successfully." -ForegroundColor Green
}
catch {
Write-Host "Failed to set Administrator password. Error: $_" -ForegroundColor Red
Exit
}
# Promote to Domain Controller
Install-ADDSForest `
-DomainName $DomainName `
-DomainNetbiosName ($DomainName.Split('.')[0].ToUpper()) `
-CreateDnsDelegation:$false `
-DatabasePath "C:\Windows\NTDS" `
-LogPath "C:\Windows\NTDS" `
-SysvolPath "C:\Windows\SYSVOL" `
-InstallDns:$true `
-SafeModeAdministratorPassword (Read-Host -AsSecureString "Enter Safe Mode (DSRM) password") `
-Force:$true