Provisioning fixes: auth-based readiness, domain join guards, site push

- wait for WinRM with an authenticated call, not a TCP probe: the port opens
  before the service can authenticate
- skip promotion/join when the machine is already there, so provision is
  idempotent
- probe the domain with System.DirectoryServices: Get-ADDomain needs RSAT,
  which a member server does not have
- passwords must not contain the account name (Legault2024! is rejected)
- Web-Dir-Browsing is the real feature name
- push the site over SMB from C$: WinRM caps the command line at 8 KB
This commit is contained in:
2026-10-21 20:02:43 -04:00
parent bb8a6a6eb0
commit 645adea875
9 changed files with 83 additions and 34 deletions
+4 -5
View File
@@ -27,14 +27,14 @@ try {
# ------------------------------------------------------------ users
$users = @(
@{ Sam='m.legault'; Given='Marie'; Surname='Legault'; Pwd='Legault2024!'; OU='TI'; Title='Directrice des TI' }
@{ Sam='s.bergeron'; Given='Sophie'; Surname='Bergeron'; Pwd='Bergeron2024!'; OU='TI'; Title='Technicienne, soutien aux usagers' }
@{ Sam='m.legault'; Given='Marie'; Surname='Legault'; Pwd='Maple2024!'; OU='TI'; Title='Directrice des TI' }
@{ Sam='s.bergeron'; Given='Sophie'; Surname='Bergeron'; Pwd='Nuage2024!'; OU='TI'; Title='Technicienne, soutien aux usagers' }
@{ Sam='helpdesk1'; Given='Sylvie'; Surname='Tremblay'; Pwd='Welcome2024!'; OU='TI'; Title='Compte partage du helpdesk' }
@{ Sam='svc_backup'; Given='Service'; Surname='Sauvegarde'; Pwd='Backup2023!'; OU='TI'; Title='Compte de service, sauvegarde' }
@{ Sam='t.smith'; Given='Thomas'; Surname='Smith'; Pwd='Str0ngAdmin!2026'; OU='TI'; Title='Administrateur de domaine' }
@{ Sam='j.contractor'; Given='Jacques'; Surname='Contractor'; Pwd='Winter2024!'; OU='Utilisateurs'; Title='Consultant, migration' }
@{ Sam='a.gagnon'; Given='Annie'; Surname='Gagnon'; Pwd='Gagnon2023!'; OU='Utilisateurs'; Title='Comptabilite' }
@{ Sam='p.roy'; Given='Pierre'; Surname='Roy'; Pwd='Roy2022!'; OU='Utilisateurs'; Title='Analyste, operations' }
@{ Sam='a.gagnon'; Given='Annie'; Surname='Gagnon'; Pwd='Riviere2023!'; OU='Utilisateurs'; Title='Comptabilite' }
@{ Sam='p.roy'; Given='Pierre'; Surname='Roy'; Pwd='Foret2022!'; OU='Utilisateurs'; Title='Analyste, operations' }
)
foreach ($u in $users) {
@@ -145,7 +145,6 @@ try {
}
Write-LabLog 'dc01: advanced audit policy enabled'
$null = schtasks.exe /Delete /TN 'NorbourgDcPost' /F
Complete-Stage $self 'ok'
} catch {
Fail-Stage $self $_.Exception.Message
+6 -10
View File
@@ -8,6 +8,12 @@ $self = $PSCommandPath
Write-LabLog 'dc01: stage 1 starting'
try {
# Re-running provision must not try to promote a server that already is one.
if ((Get-Service NTDS -ErrorAction SilentlyContinue).Status -eq 'Running') {
Complete-Stage $self 'ok already-dc'
return
}
$feature = Get-WindowsFeature -Name AD-Domain-Services
if (-not $feature.Installed) {
Write-LabLog 'dc01: installing AD-Domain-Services'
@@ -16,14 +22,6 @@ try {
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'
@@ -32,8 +30,6 @@ try {
-DomainNetbiosName '@@NETBIOS@@' `
-InstallDns `
-SafeModeAdministratorPassword $safeMode `
-ForestMode WinThreshold `
-DomainMode WinThreshold `
-NoRebootOnCompletion `
-Force
+8 -1
View File
@@ -8,9 +8,16 @@ $self = $PSCommandPath
Write-LabLog 'fs01: starting'
try {
# Re-running provision must not try to join a machine that already joined.
if ((Get-CimInstance Win32_ComputerSystem).Domain -eq '@@DOMAIN@@') {
Write-LabLog 'fs01: already joined'
Complete-Stage $self 'ok'
return
}
$features = @(
'Web-Server', 'Web-Common-Http', 'Web-Default-Doc',
'Web-Static-Content', 'Web-Directory-Browsing', 'Web-Http-Logging'
'Web-Static-Content', 'Web-Dir-Browsing', 'Web-Http-Logging'
)
foreach ($f in $features) {
if (-not (Get-WindowsFeature -Name $f).Installed) {
-1
View File
@@ -33,7 +33,6 @@ try {
Set-Acl -Path $flagDir -AclObject $acl
Write-LabLog 'ws01: user.txt in place'
$null = schtasks.exe /Delete /TN 'NorbourgWsPost' /F
Complete-Stage $self 'ok'
} catch {
Fail-Stage $self $_.Exception.Message
+6 -5
View File
@@ -8,11 +8,12 @@ $self = $PSCommandPath
Write-LabLog 'ws01: starting'
try {
$post = Join-Path $PSScriptRoot 'ws01-post.ps1'
if (-not (Test-Path $post)) { Fail-Stage $self 'ws01-post.ps1 missing' }
$null = schtasks.exe /Create /TN 'NorbourgWsPost' /F /SC ONSTART /RU SYSTEM /RL HIGHEST `
/TR "powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"$post`""
# Re-running provision must not try to join a machine that already joined.
if ((Get-CimInstance Win32_ComputerSystem).Domain -eq '@@DOMAIN@@') {
Write-LabLog 'ws01: already joined'
Complete-Stage $self 'ok'
return
}
$cred = New-Object System.Management.Automation.PSCredential(
'@@DOMAIN@@\Administrator',