- 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
31 lines
976 B
PowerShell
31 lines
976 B
PowerShell
# Norbourg lab — WS01: domain-joined workstation.
|
|
# Stage 2 runs after the join reboot because local group membership needs the
|
|
# domain group to resolve.
|
|
|
|
. "$PSScriptRoot\..\lib\common.ps1"
|
|
|
|
$self = $PSCommandPath
|
|
Write-LabLog 'ws01: 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 'ws01: already joined'
|
|
Complete-Stage $self 'ok'
|
|
return
|
|
}
|
|
|
|
$cred = New-Object System.Management.Automation.PSCredential(
|
|
'@@DOMAIN@@\Administrator',
|
|
(ConvertTo-SecureString '@@ADMIN_PASSWORD@@' -AsPlainText -Force))
|
|
|
|
Write-LabLog 'ws01: joining the domain'
|
|
Add-Computer -DomainName '@@DOMAIN@@' -Credential $cred `
|
|
-OUPath 'OU=Ordinateurs,OU=Norbourg,@@BASE_DN@@' -Force
|
|
|
|
Complete-Stage $self 'ok reboot'
|
|
Restart-Computer -Force
|
|
} catch {
|
|
Fail-Stage $self $_.Exception.Message
|
|
}
|