dc01 promotes the forest then runs a startup-scheduled post stage for OUs, users, groups, the SPN on svc_backup, pre-auth disabled on j.contractor, GenericAll over t.smith, the www A record, flags and advanced audit policy. fs01 installs IIS, shares the web root's public/ as \\FS01\Public and joins. ws01 joins, then adds WS Admins to local Administrators. provision uploads over WinRM, starts scripts detached, waits on a .done marker and survives the promotion reboot.
45 lines
1.6 KiB
PowerShell
45 lines
1.6 KiB
PowerShell
# Norbourg lab — DC01 stage 1: install AD DS and create the forest.
|
|
# Promotion reboots the machine, so the account/ACL work lives in dc01-post.ps1
|
|
# and is scheduled as a startup task before the reboot.
|
|
|
|
. "$PSScriptRoot\..\lib\common.ps1"
|
|
|
|
$self = $PSCommandPath
|
|
Write-LabLog 'dc01: stage 1 starting'
|
|
|
|
try {
|
|
$feature = Get-WindowsFeature -Name AD-Domain-Services
|
|
if (-not $feature.Installed) {
|
|
Write-LabLog 'dc01: installing AD-Domain-Services'
|
|
$null = Install-WindowsFeature -Name AD-Domain-Services -IncludeManagementTools
|
|
} else {
|
|
Write-LabLog 'dc01: AD-Domain-Services already installed'
|
|
}
|
|
|
|
$post = Join-Path $PSScriptRoot 'dc01-post.ps1'
|
|
if (-not (Test-Path $post)) { Fail-Stage $self 'dc01-post.ps1 missing next to dc01.ps1' }
|
|
|
|
# Run the account/ACL stage once, at next startup, as SYSTEM.
|
|
$null = schtasks.exe /Create /TN 'NorbourgDcPost' /F /SC ONSTART /RU SYSTEM /RL HIGHEST `
|
|
/TR "powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"$post`""
|
|
Write-LabLog 'dc01: scheduled dc01-post.ps1 at startup'
|
|
|
|
$safeMode = ConvertTo-SecureString '@@SAFE_MODE_PASSWORD@@' -AsPlainText -Force
|
|
|
|
Write-LabLog 'dc01: creating forest norbourg.lab'
|
|
$null = Install-ADDSForest `
|
|
-DomainName '@@DOMAIN@@' `
|
|
-DomainNetbiosName '@@NETBIOS@@' `
|
|
-InstallDns `
|
|
-SafeModeAdministratorPassword $safeMode `
|
|
-ForestMode WinThreshold `
|
|
-DomainMode WinThreshold `
|
|
-NoRebootOnCompletion `
|
|
-Force
|
|
|
|
Complete-Stage $self 'ok reboot'
|
|
Restart-Computer -Force
|
|
} catch {
|
|
Fail-Stage $self $_.Exception.Message
|
|
}
|