feat(stagging): prepare Windows staging server in version 0.2.0
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
- Proxmox VE: `answer.toml`
|
||||
- VMware ESXi: `ks.cfg`
|
||||
|
||||
System und Version kommen aus dem Blatt **Server**. Die Windows-Server-Version und die Mediennamen kommen aus **Staging**. Das Programm installiert selbst noch keine Server und richtet noch keinen DHCP-, PXE- oder Webdienst ein.
|
||||
System und Version kommen aus dem Blatt **Server**. Die Windows-Server-Version und die Mediennamen kommen aus **Staging**. Der Generator installiert selbst noch keine Server. Für Netzwerk und DHCP zuerst [Windows Server vorbereiten](WINDOWS-SETUP.md). PXE- und Webdienst sind noch nicht implementiert.
|
||||
|
||||
## 1. Excel ausfüllen
|
||||
|
||||
|
||||
@@ -8,6 +8,15 @@ Neue Änderungen werden unter `Unveröffentlicht` gesammelt. Bei einem neuen Ver
|
||||
|
||||
Noch keine weiteren Änderungen.
|
||||
|
||||
## 0.2.0 – 2026-09-08
|
||||
|
||||
- `Setup-StagingServer.ps1` zur Vorbereitung des bereits installierten Windows Servers aus dem KIS-Workbook.
|
||||
- Vorschau ohne Änderungen; Einrichtung mit `-Apply`, optionale DHCP-Aktivierung mit `-ActivateDhcp`.
|
||||
- Feste IPv4-Adresse, DHCP-Rolle, eigener Bereich, Adapterbindung, Firewall-Regel und lokale Verzeichnisse.
|
||||
- Prüfung auf passende Windows-Version, dedizierten physischen Adapter, Netzkonflikte und fremde DHCP-Konfiguration.
|
||||
- Ausgangszustand und Ergebnis in lokalen, aus Git ausgeschlossenen Laufordnern; einfache Bedienanleitung.
|
||||
- 46 zusätzliche Prüfungen mit simulierten Windows-Befehlen; reale Windows-/GETAC-Abnahme steht aus. PXE-Dienst und Bootdateien sind noch nicht umgesetzt.
|
||||
|
||||
## 0.1.0 – 2026-09-08
|
||||
|
||||
Erster ausdrücklich versionierter Programmstand. Die vorherigen Entwurfsstände sind damit dokumentiert, aber nicht nachträglich als veröffentlichte Git-Versionen oder Tags ausgegeben.
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference='Stop'
|
||||
Import-Module (Join-Path $PSScriptRoot 'Unattended.psm1') -DisableNameChecking
|
||||
|
||||
function ConvertTo-IPv4Value([string]$Address) {
|
||||
if ($Address -notmatch '^(0|[1-9][0-9]{0,2})(\.(0|[1-9][0-9]{0,2})){3}$') { throw "Ungueltige IPv4-Adresse: $Address" }
|
||||
[uint64]$v=0
|
||||
foreach ($p in $Address.Split('.')) { if ([int]$p -gt 255) { throw "Ungueltige IPv4-Adresse: $Address" }; $v=256*$v+[int]$p }
|
||||
return $v
|
||||
}
|
||||
function ConvertFrom-IPv4Value([uint64]$Value) {
|
||||
return (@(24,16,8,0 | ForEach-Object { ($Value -shr $_) -band 255 }) -join '.')
|
||||
}
|
||||
function Get-WindowsPreparationPlan($Settings) {
|
||||
foreach ($key in @('Windows-Server-Version','Netzwerkkarte','GETAC-IP','Netzpräfix','DHCP von','DHCP bis','Medienordner')) {
|
||||
if ([string]::IsNullOrWhiteSpace($Settings[$key])) { throw "Staging: '$key' fehlt." }
|
||||
}
|
||||
$year=([string]$Settings['Windows-Server-Version']).Trim()
|
||||
if ($year -notmatch '^(?:Windows Server )?(2019|2022|2025)$') { throw 'Windows-Server-Version: 2019, 2022 oder 2025 eintragen. Andere Versionen sind noch nicht vorbereitet.' }
|
||||
$year=$Matches[1]
|
||||
$adapter=([string]$Settings.Netzwerkkarte).Trim()
|
||||
if ($adapter -match '[*?\[\]\x00-\x1f]') { throw 'Netzwerkkarte: exakten Adapternamen ohne Wildcards eintragen.' }
|
||||
if ($Settings['Netzpräfix'] -notmatch '^(?:[1-9]|[12][0-9]|30)$') { throw 'Netzpraefix muss zwischen 1 und 30 liegen.' }
|
||||
$prefix=[int]$Settings['Netzpräfix']; $ip=ConvertTo-IPv4Value $Settings['GETAC-IP']
|
||||
[uint64]$size=[Math]::Pow(2,32-$prefix); [uint64]$network=[Math]::Floor($ip/$size)*$size; $broadcast=$network+$size-1
|
||||
$first=ConvertTo-IPv4Value $Settings['DHCP von']; $last=ConvertTo-IPv4Value $Settings['DHCP bis']
|
||||
if ($ip -le $network -or $ip -ge $broadcast -or $first -le $network -or $last -ge $broadcast -or $first -gt $last -or ($ip -ge $first -and $ip -le $last)) { throw 'GETAC-IP und DHCP-Bereich muessen getrennte nutzbare Adressen desselben Netzes sein.' }
|
||||
$octet=$ip -shr 24
|
||||
if ($octet -eq 0 -or $octet -eq 127 -or $octet -ge 224 -or (($ip -shr 16) -eq 43518)) { throw 'GETAC-IP darf keine Loopback-, APIPA-, Multicast- oder reservierte Adresse sein.' }
|
||||
$media=([string]$Settings.Medienordner).Trim().TrimEnd('\')
|
||||
if ($media -notmatch '^[a-zA-Z]:\\[^<>:"|?*\x00-\x1f]+$' -or $media -match '(?:^|\\)\.{1,2}(?:\\|$)' -or $media -match '[. ](?:\\|$)') { throw 'Medienordner: lokalen absoluten Unterordner verwenden, z.B. C:\Staging\Medien.' }
|
||||
# Kept separate from media: never put secret answer files in a future webroot.
|
||||
$drive=$media.Substring(0,2)
|
||||
return [pscustomobject]@{ WindowsYear=$year; Adapter=$adapter; IP=[string]$Settings['GETAC-IP']; Prefix=$prefix; ScopeId=(ConvertFrom-IPv4Value $network); SubnetMask=(Get-Netmask $prefix); DHCPStart=[string]$Settings['DHCP von']; DHCPEnd=[string]$Settings['DHCP bis']; MediaDirectory=$media; BootDirectory="$drive\Staging-PXE\Boot"; ScopeName='Stagging-KIS'; ScopeDescription='Managed by Stagging Setup-StagingServer v1' }
|
||||
}
|
||||
|
||||
function Assert-PreparationState($Plan,$State) {
|
||||
if ($State.ProductType -ne 3) { throw 'Ein eigenstaendiger Windows Server ist erforderlich; kein Client und kein Domain Controller.' }
|
||||
if ($State.PartOfDomain) { throw 'Dieses KIS-Profil ist fuer einen eigenstaendigen Staging-Server. Domaenen-DHCP/AD-Autorisierung nicht automatisch aendern.' }
|
||||
if ($State.Caption -notmatch ("Windows Server.*"+[regex]::Escape($Plan.WindowsYear))) { throw "Windows-Version passt nicht zur Excel ($($Plan.WindowsYear))." }
|
||||
if (@($State.Adapters).Count -ne 1) { throw 'Netzwerkkarte nicht eindeutig gefunden.' }
|
||||
$adapter=@($State.Adapters)[0]
|
||||
if (-not $adapter.HardwareInterface -or $adapter.Status -ne 'Up') { throw 'Der ausgewaehlte physische Netzwerkadapter muss verbunden sein (Status Up).' }
|
||||
if (@($State.DefaultRoutes).Count -gt 0) { throw 'Der Installationsadapter hat ein Standardgateway. Einen dedizierten Adapter ohne Standardroute verwenden.' }
|
||||
foreach ($a in $State.Addresses) {
|
||||
if ($a.PrefixOrigin -eq 'Manual' -and ($a.IPAddress -ne $Plan.IP -or [int]$a.PrefixLength -ne $Plan.Prefix)) { throw 'Abweichende feste IP am Installationsadapter. Vorhandene manuelle Konfiguration wird nicht ersetzt.' }
|
||||
}
|
||||
foreach ($a in $State.OtherAddresses) {
|
||||
if ($a.IPAddress -eq $Plan.IP) { throw 'GETAC-IP ist bereits an einem anderen Adapter konfiguriert.' }
|
||||
$value=ConvertTo-IPv4Value ([string]$a.IPAddress); $otherPrefix=[int]$a.PrefixLength
|
||||
$size=[Math]::Pow(2,32-$otherPrefix); $low=[Math]::Floor($value/$size)*$size; $high=$low+$size-1
|
||||
$ourLow=ConvertTo-IPv4Value $Plan.ScopeId; $ourHigh=$ourLow+[Math]::Pow(2,32-$Plan.Prefix)-1
|
||||
if ($low -le $ourHigh -and $high -ge $ourLow) { throw 'Das Installationsnetz ueberlappt ein Netz an einem anderen Adapter.' }
|
||||
}
|
||||
foreach ($scope in $State.Scopes) {
|
||||
if ([string]$scope.ScopeId -ne $Plan.ScopeId -or $scope.Name -ne $Plan.ScopeName -or $scope.Description -ne $Plan.ScopeDescription) { throw 'Vorhandener fremder DHCP-Bereich: keine automatische Uebernahme.' }
|
||||
if ([string]$scope.StartRange -ne $Plan.DHCPStart -or [string]$scope.EndRange -ne $Plan.DHCPEnd -or [string]$scope.SubnetMask -ne $Plan.SubnetMask) { throw 'Vorhandener Staging-Bereich weicht von Excel ab. Kein automatisches Ersetzen bestehender Leases.' }
|
||||
}
|
||||
if (@($State.Scopes6).Count -gt 0) { throw 'Vorhandene DHCPv6-Bereiche: kein dedizierter leerer Staging-DHCP-Server.' }
|
||||
if (@($State.Options).Count -gt 0) { throw 'Vorhandene DHCP-Optionen: vor automatischer Einrichtung manuell pruefen (keine impliziten Router-/PXE-Optionen).' }
|
||||
}
|
||||
|
||||
function Get-PreparationState($Plan) {
|
||||
$os=Get-CimInstance Win32_OperatingSystem
|
||||
$computer=Get-CimInstance Win32_ComputerSystem
|
||||
$adapters=@(Get-NetAdapter -Physical | Where-Object { $_.Name -ceq $Plan.Adapter })
|
||||
$addresses=@(); $routes=@(); $ipInterface=@(); $dnsClient=@()
|
||||
if ($adapters.Count -eq 1) {
|
||||
$addresses=@(Get-NetIPAddress -InterfaceIndex $adapters[0].ifIndex -AddressFamily IPv4 -ErrorAction Stop)
|
||||
$routes=@(Get-NetRoute -InterfaceIndex $adapters[0].ifIndex -AddressFamily IPv4 | Where-Object DestinationPrefix -eq '0.0.0.0/0')
|
||||
$ipInterface=@(Get-NetIPInterface -InterfaceIndex $adapters[0].ifIndex -AddressFamily IPv4)
|
||||
$dnsClient=@(Get-DnsClient -InterfaceIndex $adapters[0].ifIndex)
|
||||
}
|
||||
$others=@(Get-NetIPAddress -AddressFamily IPv4 | Where-Object { $_.InterfaceAlias -cne $Plan.Adapter -and $_.IPAddress -ne '127.0.0.1' })
|
||||
$feature=Get-WindowsFeature -Name DHCP
|
||||
$scopes=@(); $scopes6=@(); $bindings=@(); $options=@()
|
||||
if ($feature.Installed) {
|
||||
Import-Module DhcpServer
|
||||
$scopes=@(Get-DhcpServerv4Scope); $scopes6=@(Get-DhcpServerv6Scope); $bindings=@(Get-DhcpServerv4Binding)
|
||||
$options=@(Get-DhcpServerv4OptionValue)
|
||||
foreach ($scope in $scopes) { $options+=@(Get-DhcpServerv4OptionValue -ScopeId $scope.ScopeId) }
|
||||
}
|
||||
return [pscustomobject]@{ Caption=$os.Caption; ProductType=$os.ProductType; PartOfDomain=$computer.PartOfDomain; Adapters=$adapters; Addresses=$addresses; IPInterface=$ipInterface; DnsClient=$dnsClient; OtherAddresses=$others; DefaultRoutes=$routes; Scopes=$scopes; Scopes6=$scopes6; Options=$options; Bindings=$bindings; DhcpInstalled=[bool]$feature.Installed }
|
||||
}
|
||||
|
||||
function Invoke-WindowsPreparation($Plan,$State,[switch]$ActivateDhcp) {
|
||||
Assert-PreparationState $Plan $State
|
||||
$index=$State.Adapters[0].ifIndex
|
||||
if (-not $State.DhcpInstalled) {
|
||||
$installed=Install-WindowsFeature -Name DHCP -IncludeManagementTools
|
||||
if (-not $installed.Success) { throw 'DHCP-Rolle konnte nicht installiert werden.' }
|
||||
if ([string]$installed.RestartNeeded -eq 'Yes') { throw 'DHCP-Rolle installiert. Windows lokal neu starten und dasselbe Skript erneut ausfuehren; kein automatischer Neustart.' }
|
||||
}
|
||||
Import-Module DhcpServer
|
||||
Start-Service -Name DHCPServer
|
||||
$scopeCreated=$false
|
||||
try {
|
||||
# First disable all DHCP bindings and the owned scope, before changing IPs.
|
||||
foreach ($binding in @(Get-DhcpServerv4Binding)) { Set-DhcpServerv4Binding -InterfaceAlias $binding.InterfaceAlias -BindingState $false }
|
||||
foreach ($binding in @(Get-DhcpServerv6Binding)) { Set-DhcpServerv6Binding -InterfaceAlias $binding.InterfaceAlias -BindingState $false }
|
||||
if (@($State.Scopes).Count -gt 0) { Set-DhcpServerv4Scope -ScopeId $Plan.ScopeId -State InActive; $scopeCreated=$true }
|
||||
Set-NetIPInterface -InterfaceIndex $index -AddressFamily IPv4 -Dhcp Disabled
|
||||
foreach ($address in @(Get-NetIPAddress -InterfaceIndex $index -AddressFamily IPv4)) {
|
||||
if ($address.IPAddress -ne $Plan.IP -or $address.PrefixOrigin -ne 'Manual') { Remove-NetIPAddress -InterfaceIndex $index -IPAddress $address.IPAddress -Confirm:$false }
|
||||
}
|
||||
$matching=@($State.Addresses | Where-Object { $_.IPAddress -eq $Plan.IP -and [int]$_.PrefixLength -eq $Plan.Prefix -and $_.PrefixOrigin -eq 'Manual' })
|
||||
if ($matching.Count -eq 0) {
|
||||
New-NetIPAddress -InterfaceIndex $index -IPAddress $Plan.IP -PrefixLength $Plan.Prefix -AddressFamily IPv4 | Out-Null
|
||||
}
|
||||
# Wait for duplicate address detection, but do not continue after a conflict.
|
||||
$ready=$false
|
||||
for ($i=0; $i -lt 10; $i++) {
|
||||
$address=Get-NetIPAddress -InterfaceIndex $index -AddressFamily IPv4 | Where-Object IPAddress -eq $Plan.IP
|
||||
if ($null -ne $address -and $address.AddressState -eq 'Duplicate') { throw 'Doppelte GETAC-IP im Netz erkannt.' }
|
||||
if ($null -ne $address -and $address.AddressState -eq 'Preferred') { $ready=$true; break }
|
||||
Start-Sleep -Seconds 1
|
||||
}
|
||||
if (-not $ready) { throw 'GETAC-IP ist noch nicht verwendbar. Verkabelung/IP-Konflikt pruefen.' }
|
||||
Set-DnsClient -InterfaceIndex $index -RegisterThisConnectionsAddress $false
|
||||
foreach ($path in @($Plan.MediaDirectory,$Plan.BootDirectory)) { New-Item -ItemType Directory -Path $path -Force | Out-Null }
|
||||
if (-not $scopeCreated) {
|
||||
Add-DhcpServerv4Scope -Name $Plan.ScopeName -Description $Plan.ScopeDescription -StartRange $Plan.DHCPStart -EndRange $Plan.DHCPEnd -SubnetMask $Plan.SubnetMask -State InActive -LeaseDuration ([TimeSpan]::FromHours(4)) | Out-Null
|
||||
$scopeCreated=$true
|
||||
}
|
||||
Set-DhcpServerv4Binding -InterfaceAlias $Plan.Adapter -BindingState $true
|
||||
# Install-WindowsFeature provides DHCP service firewall rules. Add an
|
||||
# explicit adapter-bound rule so an isolated Public-profile NIC works.
|
||||
$ruleName='Stagging-KIS-DHCPv4'
|
||||
$rule=Get-NetFirewallRule -Name $ruleName -ErrorAction SilentlyContinue
|
||||
if ($rule) { Remove-NetFirewallRule -Name $ruleName }
|
||||
New-NetFirewallRule -Name $ruleName -DisplayName 'Stagging KIS DHCPv4' -Direction Inbound -Action Allow -Protocol UDP -LocalPort 67 -RemotePort 68 -InterfaceAlias $Plan.Adapter -Profile Any -Service DHCPServer | Out-Null
|
||||
Set-Service -Name DHCPServer -StartupType Automatic
|
||||
$bindings=@(Get-DhcpServerv4Binding)
|
||||
$target=@($bindings | Where-Object { $_.InterfaceAlias -eq $Plan.Adapter -and $_.BindingState })
|
||||
$other=@($bindings | Where-Object { $_.InterfaceAlias -ne $Plan.Adapter -and $_.BindingState })
|
||||
if ($target.Count -ne 1 -or $other.Count -gt 0) { throw 'DHCP-Bindings entsprechen nicht dem Installationsadapter.' }
|
||||
if ($ActivateDhcp) { Set-DhcpServerv4Scope -ScopeId $Plan.ScopeId -State Active }
|
||||
$scope=Get-DhcpServerv4Scope -ScopeId $Plan.ScopeId
|
||||
$expected=if ($ActivateDhcp) { 'Active' } else { 'InActive' }
|
||||
if ([string]$scope.State -ne $expected) { throw 'DHCP-Bereich hat nicht den erwarteten Zustand.' }
|
||||
return [pscustomobject]@{ IP=$Plan.IP; Adapter=$Plan.Adapter; DHCP=$expected; ScopeId=$Plan.ScopeId; BootFiles='Noch nicht bereitgestellt'; MediaDirectory=$Plan.MediaDirectory; BootDirectory=$Plan.BootDirectory }
|
||||
} catch {
|
||||
if ($scopeCreated) { Set-DhcpServerv4Scope -ScopeId $Plan.ScopeId -State InActive -ErrorAction SilentlyContinue }
|
||||
Stop-Service -Name DHCPServer -ErrorAction SilentlyContinue
|
||||
throw
|
||||
}
|
||||
}
|
||||
Export-ModuleMember -Function Get-WindowsPreparationPlan,Assert-PreparationState,Get-PreparationState,Invoke-WindowsPreparation
|
||||
+4
-2
@@ -1,12 +1,14 @@
|
||||
# Stagging
|
||||
|
||||
Projektversion: **0.1.0**. Änderungen und bekannte Grenzen stehen im [Änderungsverlauf](CHANGELOG.md). Die verbindliche Versionsnummer liegt in [VERSION](VERSION) und kann mit `./Prepare-Unattended.ps1 -ShowVersion` angezeigt werden. Sie ist unabhängig von den Hypervisor-Versionen in Excel und vom Workbook-Schema.
|
||||
Projektversion: **0.2.0**. Änderungen und bekannte Grenzen stehen im [Änderungsverlauf](CHANGELOG.md). Die verbindliche Versionsnummer liegt in [VERSION](VERSION) und kann mit `./Prepare-Unattended.ps1 -ShowVersion` angezeigt werden. Sie ist unabhängig von den Hypervisor-Versionen in Excel und vom Workbook-Schema.
|
||||
|
||||
## Aktueller Programmstand
|
||||
|
||||
Der erste Baustein für unbeaufsichtigte Installationen ist implementiert: `Prepare-Unattended.ps1` liest das KIS-Workbook ohne Excel-Abhängigkeit, prüft ausgewählte Server und erzeugt nach interaktiver Bestätigung PVE-`answer.toml` beziehungsweise ESXi-`ks.cfg`. Die gewünschten Versionen kommen ausschließlich aus Excel. Passwörter werden verdeckt abgefragt und als gesalzene Hashes in die Antwortdateien geschrieben.
|
||||
|
||||
Die [Anleitung](ANLEITUNG.md) beschreibt Prüfung und Dateierzeugung. DHCP/PXE, Medienvorbereitung, Auslieferung und reale Installertests sind noch offen. Auf dem GETAC wurde nichts installiert oder gestartet.
|
||||
**Erster Schritt:** [Windows Server vorbereiten](WINDOWS-SETUP.md) mit `Setup-StagingServer.ps1`. Das Skript übernimmt Netzwerkwerte aus Excel, richtet DHCP und die lokalen Verzeichnisse ein. Standardmäßig wird nur geprüft; die Einrichtung erfolgt mit `-Apply`.
|
||||
|
||||
Die [Anleitung](ANLEITUNG.md) beschreibt anschließend Prüfung und Dateierzeugung für die Hypervisoren. PXE-Dienst, Medienvorbereitung, Auslieferung und reale Installertests sind noch offen. Auf dem GETAC wurde durch die Entwicklung nichts installiert oder gestartet.
|
||||
|
||||
## Projektauftrag
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#requires -Version 5.1
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$Workbook=(Join-Path $PSScriptRoot 'outputs/01a07d3f/ConfigWorkbook_KIS.xlsx'),
|
||||
[switch]$Apply,
|
||||
[switch]$ActivateDhcp,
|
||||
[switch]$ShowVersion
|
||||
)
|
||||
$ErrorActionPreference='Stop'
|
||||
$version=(Get-Content -LiteralPath (Join-Path $PSScriptRoot 'VERSION') -Raw).Trim()
|
||||
if ($ShowVersion) { $version; return }
|
||||
if ($ActivateDhcp -and -not $Apply) { throw '-ActivateDhcp erfordert -Apply.' }
|
||||
Import-Module (Join-Path $PSScriptRoot 'Modules/Unattended.psm1') -DisableNameChecking
|
||||
Import-Module (Join-Path $PSScriptRoot 'Modules/WindowsPreparation.psm1') -Force -DisableNameChecking
|
||||
$config=Read-KisWorkbook $Workbook
|
||||
$plan=Get-WindowsPreparationPlan $config.Settings
|
||||
Write-Host "Staging $version - Windows-Server-Vorbereitung"
|
||||
$plan | Format-List | Out-Host
|
||||
if ([Environment]::OSVersion.Platform -ne [PlatformID]::Win32NT) {
|
||||
if ($Apply) { throw 'Einrichtung muss lokal auf dem GETAC unter Windows Server laufen.' }
|
||||
Write-Host 'Nur Excel-Plan geprueft. Windows-/Adapterpruefung erfolgt auf dem GETAC.'; return
|
||||
}
|
||||
if ($PSVersionTable.PSEdition -ne 'Desktop') { throw 'Auf dem GETAC Windows PowerShell 5.1 (powershell.exe) verwenden.' }
|
||||
$identity=[Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
$principal=New-Object Security.Principal.WindowsPrincipal($identity)
|
||||
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { throw 'Windows PowerShell lokal als Administrator starten.' }
|
||||
Import-Module ServerManager
|
||||
$state=Get-PreparationState $plan
|
||||
Assert-PreparationState $plan $state
|
||||
Write-Host 'Windows und Adapter geprueft. Kein Standardgateway auf dem Installationsadapter; andere Adapter bleiben fuer Verwaltung/Internet bestehen.'
|
||||
if (-not $Apply) { Write-Host 'Vorschau beendet. -Apply richtet ein; -Apply -ActivateDhcp aktiviert ausserdem den DHCP-Bereich.'; return }
|
||||
Write-Host 'Lokal am GETAC ausfuehren: Die IPv4-Konfiguration des Installationsadapters wird umgestellt.'
|
||||
Write-Host 'Nur mit dem separaten Installations-Switch verbinden. DHCP-Bindings anderer Adapter werden deaktiviert.'
|
||||
if ($ActivateDhcp) { Write-Host 'DHCP wird am Installationsadapter aktiv und vergibt danach Adressen.' }
|
||||
if ((Read-Host 'Zum Einrichten EINRICHTEN eingeben') -cne 'EINRICHTEN') { Write-Host 'Abgebrochen.'; return }
|
||||
$backup=New-PrivateRunDirectory (Join-Path $PSScriptRoot 'runs/windows-setup')
|
||||
$encoding=New-Object Text.UTF8Encoding($false)
|
||||
[IO.File]::WriteAllText((Join-Path $backup 'before.json'),($state | ConvertTo-Json -Depth 8),$encoding)
|
||||
[IO.File]::WriteAllText((Join-Path $backup 'plan.json'),($plan | ConvertTo-Json -Depth 5),$encoding)
|
||||
try {
|
||||
$result=Invoke-WindowsPreparation $plan $state -ActivateDhcp:$ActivateDhcp
|
||||
[IO.File]::WriteAllText((Join-Path $backup 'result.json'),($result | ConvertTo-Json),$encoding)
|
||||
$result | Format-List | Out-Host
|
||||
Write-Host "Vorbereitung abgeschlossen. Ausgangszustand und Ergebnis: $backup"
|
||||
Write-Host 'PXE/TFTP-Bootdienst und Hypervisor-Bootdateien folgen als naechster Schritt. Noch kein Netzwerkboot moeglich.'
|
||||
} catch {
|
||||
Write-Host "Einrichtung nicht abgeschlossen. Ausgangszustand: $backup. Keine automatische Ruecksetzung der Netzwerkadresse."
|
||||
throw
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
#requires -Version 5.1
|
||||
$ErrorActionPreference='Stop'
|
||||
Import-Module (Join-Path $PSScriptRoot '../Modules/WindowsPreparation.psm1') -Force -DisableNameChecking
|
||||
$script:count=0
|
||||
function Assert($Condition,$Label) { if (-not $Condition) { throw "FAIL: $Label" }; $script:count++ }
|
||||
function Reject([scriptblock]$Action,$Label) { $failed=$false; try { & $Action | Out-Null } catch { $failed=$true }; Assert $failed $Label }
|
||||
function Settings { return @{ 'Windows-Server-Version'='2025'; Netzwerkkarte='Ethernet'; 'GETAC-IP'='192.168.50.1'; 'Netzpräfix'='24'; 'DHCP von'='192.168.50.100'; 'DHCP bis'='192.168.50.199'; Medienordner='C:\Staging\Medien' } }
|
||||
function State { return [pscustomobject]@{ Caption='Microsoft Windows Server 2025 Standard'; ProductType=3; PartOfDomain=$false; Adapters=@([pscustomobject]@{ Name='Ethernet'; ifIndex=4; HardwareInterface=$true; Status='Up' }); Addresses=@(); OtherAddresses=@(); DefaultRoutes=@(); Scopes=@(); Scopes6=@(); Options=@(); Bindings=@(); DhcpInstalled=$false } }
|
||||
$plan=Get-WindowsPreparationPlan (Settings)
|
||||
Assert ($plan.ScopeId -eq '192.168.50.0') 'Scope network'
|
||||
Assert ($plan.SubnetMask -eq '255.255.255.0') 'Subnet mask'
|
||||
Assert ($plan.WindowsYear -eq '2025') 'Version from Excel'
|
||||
Assert ($plan.MediaDirectory -eq 'C:\Staging\Medien') 'Media path from Excel'
|
||||
Assert ($plan.BootDirectory -eq 'C:\Staging-PXE\Boot') 'Separate boot directory'
|
||||
Assert-PreparationState $plan (State); Assert $true 'Fresh dedicated server accepted'
|
||||
foreach ($key in @('Windows-Server-Version','Netzwerkkarte','GETAC-IP','Netzpräfix','DHCP von','DHCP bis','Medienordner')) { Reject { $s=Settings; $s[$key]=''; Get-WindowsPreparationPlan $s } "Missing $key" }
|
||||
Reject { $s=Settings; $s['Windows-Server-Version']='2030'; Get-WindowsPreparationPlan $s } 'Unknown Windows version'
|
||||
Reject { $s=Settings; $s.Netzwerkkarte='Ether*'; Get-WindowsPreparationPlan $s } 'Adapter wildcard'
|
||||
Reject { $s=Settings; $s['GETAC-IP']='192.168.50.100'; Get-WindowsPreparationPlan $s } 'IP in pool'
|
||||
Reject { $s=Settings; $s['DHCP von']='192.168.50.220'; Get-WindowsPreparationPlan $s } 'Reversed pool'
|
||||
Reject { $s=Settings; $s['DHCP bis']='192.168.51.10'; Get-WindowsPreparationPlan $s } 'Pool outside subnet'
|
||||
Reject { $s=Settings; $s['GETAC-IP']='192.168.50.255'; Get-WindowsPreparationPlan $s } 'Broadcast station IP'
|
||||
Reject { $s=Settings; $s['Netzpräfix']='33'; Get-WindowsPreparationPlan $s } 'Invalid prefix'
|
||||
Reject { $s=Settings; $s.Medienordner='\\nas\media'; Get-WindowsPreparationPlan $s } 'Remote media path'
|
||||
Reject { $s=Settings; $s.Medienordner='C:\Staging\..\Windows'; Get-WindowsPreparationPlan $s } 'Path traversal'
|
||||
Reject { $s=State; $s.ProductType=1; Assert-PreparationState $plan $s } 'Windows client'
|
||||
Reject { $s=State; $s.ProductType=2; Assert-PreparationState $plan $s } 'Domain controller'
|
||||
Reject { $s=State; $s.PartOfDomain=$true; Assert-PreparationState $plan $s } 'Domain member'
|
||||
Reject { $s=State; $s.Caption='Microsoft Windows Server 2022 Standard'; Assert-PreparationState $plan $s } 'Excel/OS mismatch'
|
||||
Reject { $s=State; $s.Adapters=@(); Assert-PreparationState $plan $s } 'Missing adapter'
|
||||
Reject { $s=State; $s.Adapters[0].Status='Disconnected'; Assert-PreparationState $plan $s } 'Unplugged adapter'
|
||||
Reject { $s=State; $s.Adapters[0].HardwareInterface=$false; Assert-PreparationState $plan $s } 'Virtual adapter'
|
||||
Reject { $s=State; $s.DefaultRoutes=@('0.0.0.0/0'); Assert-PreparationState $plan $s } 'Management default route'
|
||||
Reject { $s=State; $s.Addresses=@([pscustomobject]@{ IPAddress='192.168.1.1'; PrefixLength=24; PrefixOrigin='Manual' }); Assert-PreparationState $plan $s } 'Existing static configuration'
|
||||
Reject { $s=State; $s.OtherAddresses=@([pscustomobject]@{ IPAddress='192.168.50.7'; PrefixLength=24 }); Assert-PreparationState $plan $s } 'Other adapter overlap'
|
||||
Reject { $s=State; $s.Scopes=@([pscustomobject]@{ ScopeId='10.0.0.0'; Name='Office'; Description='Other'; StartRange='10.0.0.10'; EndRange='10.0.0.99'; SubnetMask='255.255.255.0' }); Assert-PreparationState $plan $s } 'Existing production scope'
|
||||
Reject { $s=State; $s.Scopes6=@('anything'); Assert-PreparationState $plan $s } 'Existing IPv6 scope'
|
||||
Reject { $s=State; $s.Options=@('router'); Assert-PreparationState $plan $s } 'Existing global options'
|
||||
|
||||
# Windows cmdlets are mocked inside module scope. No local network/role changes.
|
||||
$module=Get-Module WindowsPreparation
|
||||
$simulation=& $module {
|
||||
param($p,$s)
|
||||
$script:events=[Collections.Generic.List[string]]::new(); $script:scopeState='InActive'; $script:binding=$false; $script:addressExists=$false
|
||||
function Import-Module { param($Name) }
|
||||
function Install-WindowsFeature { param($Name,[switch]$IncludeManagementTools) $script:events.Add('install-role'); [pscustomobject]@{ Success=$true; RestartNeeded='No' } }
|
||||
function Start-Service { param($Name) $script:events.Add('start-service') }
|
||||
function Stop-Service { param($Name,$ErrorAction) $script:events.Add('stop-service') }
|
||||
function Get-DhcpServerv4Binding { @([pscustomobject]@{ InterfaceAlias='Ethernet'; BindingState=$script:binding },[pscustomobject]@{ InterfaceAlias='Wi-Fi'; BindingState=$false }) }
|
||||
function Get-DhcpServerv6Binding { @([pscustomobject]@{ InterfaceAlias='Ethernet' }) }
|
||||
function Set-DhcpServerv4Binding { param($InterfaceAlias,$BindingState) $script:events.Add("binding:$InterfaceAlias=$BindingState"); if ($InterfaceAlias -eq 'Ethernet') { $script:binding=$BindingState } }
|
||||
function Set-DhcpServerv6Binding { param($InterfaceAlias,$BindingState) $script:events.Add("v6:$BindingState") }
|
||||
function Set-NetIPInterface { param($InterfaceIndex,$AddressFamily,$Dhcp) $script:events.Add('static-ip') }
|
||||
function Get-NetIPAddress { param($InterfaceIndex,$AddressFamily) if ($script:addressExists) { [pscustomobject]@{ IPAddress=$p.IP; AddressState='Preferred'; PrefixOrigin='Manual' } } }
|
||||
function Remove-NetIPAddress { param($InterfaceIndex,$IPAddress,$Confirm) throw 'Unexpected IP removal' }
|
||||
function New-NetIPAddress { param($InterfaceIndex,$IPAddress,$PrefixLength,$AddressFamily) $script:addressExists=$true; $script:events.Add('new-ip') }
|
||||
function Set-DnsClient { param($InterfaceIndex,$RegisterThisConnectionsAddress) }
|
||||
function New-Item { param($ItemType,$Path,[switch]$Force) $script:events.Add('directory') }
|
||||
function Add-DhcpServerv4Scope { param($Name,$Description,$StartRange,$EndRange,$SubnetMask,$State,$LeaseDuration) $script:scopeState=$State; $script:events.Add('create-scope') }
|
||||
function Get-NetFirewallRule { param($Name,$ErrorAction) }
|
||||
function New-NetFirewallRule { param($Name,$DisplayName,$Direction,$Action,$Protocol,$LocalPort,$RemotePort,$InterfaceAlias,$Profile,$Service) $script:events.Add("firewall:$InterfaceAlias/$LocalPort") }
|
||||
function Set-Service { param($Name,$StartupType) }
|
||||
function Set-DhcpServerv4Scope { param($ScopeId,$State,$ErrorAction) $script:scopeState=$State; $script:events.Add("scope:$State") }
|
||||
function Get-DhcpServerv4Scope { param($ScopeId) [pscustomobject]@{ State=$script:scopeState } }
|
||||
$first=Invoke-WindowsPreparation $p $s
|
||||
$firstEvents=@($script:events); $script:events.Clear()
|
||||
$s.DhcpInstalled=$true
|
||||
$s.Addresses=@([pscustomobject]@{ IPAddress=$p.IP; PrefixLength=$p.Prefix; PrefixOrigin='Manual' })
|
||||
$s.Scopes=@([pscustomobject]@{ ScopeId=$p.ScopeId; Name=$p.ScopeName; Description=$p.ScopeDescription; StartRange=$p.DHCPStart; EndRange=$p.DHCPEnd; SubnetMask=$p.SubnetMask })
|
||||
$second=Invoke-WindowsPreparation $p $s -ActivateDhcp
|
||||
$secondEvents=@($script:events); $script:events.Clear()
|
||||
function New-NetFirewallRule { throw 'Simulated firewall failure' }
|
||||
$failed=$false; try { Invoke-WindowsPreparation $p $s -ActivateDhcp | Out-Null } catch { $failed=$true }
|
||||
[pscustomobject]@{ First=$first; FirstEvents=$firstEvents; Second=$second; SecondEvents=$secondEvents; Failed=$failed; FailureEvents=@($script:events) }
|
||||
} $plan (State)
|
||||
Assert ($simulation.First.DHCP -eq 'InActive') 'Default leaves scope inactive'
|
||||
Assert ($simulation.FirstEvents -contains 'v6:False') 'DHCPv6 unbound'
|
||||
Assert ($simulation.FirstEvents.IndexOf('binding:Wi-Fi=False') -lt $simulation.FirstEvents.IndexOf('new-ip')) 'Unbind before network changes'
|
||||
Assert ($simulation.FirstEvents -contains 'firewall:Ethernet/67') 'Firewall bound to selected adapter'
|
||||
Assert ($simulation.Second.DHCP -eq 'Active') 'Explicit activation'
|
||||
Assert ($simulation.SecondEvents -notcontains 'install-role') 'Rerun preserves installed role'
|
||||
Assert ($simulation.SecondEvents -notcontains 'new-ip') 'Rerun preserves static IP'
|
||||
Assert ($simulation.SecondEvents -notcontains 'create-scope') 'Rerun preserves scope'
|
||||
Assert ($simulation.Failed) 'Mutation failure surfaced'
|
||||
Assert ($simulation.FailureEvents -contains 'scope:InActive') 'Failure deactivates owned scope'
|
||||
Assert ($simulation.FailureEvents -contains 'stop-service') 'Failure stops DHCP'
|
||||
Write-Host "$script:count Windows preparation checks passed (Windows cmdlets simulated)."
|
||||
+1
-1
@@ -1 +1 @@
|
||||
0.1.0
|
||||
0.2.0
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
# GETAC: Windows Server vorbereiten
|
||||
|
||||
`Setup-StagingServer.ps1` bereitet einen bereits installierten Windows Server vor. Es installiert die DHCP-Rolle, setzt die feste IPv4-Adresse am Installationsadapter und legt Medien- und Bootordner an. PXE-/TFTP-Dienst und Hypervisor-Bootdateien folgen im nächsten Schritt. Windows selbst wird mit diesem Skript nicht installiert.
|
||||
|
||||
## 1. Excel ausfüllen
|
||||
|
||||
In `outputs/01a07d3f/ConfigWorkbook_KIS.xlsx` im Blatt **Staging** diese Werte eintragen und speichern:
|
||||
|
||||
| Feld | Beispiel / Bedeutung |
|
||||
| --- | --- |
|
||||
| Windows-Server-Version | `2025` – muss der installierten Version entsprechen; vorbereitet sind 2019, 2022 und 2025 |
|
||||
| Netzwerkkarte | `Ethernet` – genauer Name des Anschlusses zum Installations-Switch |
|
||||
| GETAC-IP | `192.168.50.1` |
|
||||
| Netzpräfix | `24` |
|
||||
| DHCP von | `192.168.50.100` |
|
||||
| DHCP bis | `192.168.50.199` |
|
||||
| Medienordner | `C:\Staging\Medien` |
|
||||
|
||||
Die Netzwerkwerte sind Beispiele. Auf dem Installationsadapter darf kein Standardgateway und keine abweichende manuelle IP eingerichtet sein. Den Adapternamen zeigt `Get-NetAdapter`. Die Serverzeilen sowie PVE-/ESXi-Versionen und ISO-Namen werden für diesen Vorbereitungsschritt noch nicht benötigt.
|
||||
|
||||
## 2. Prüfen
|
||||
|
||||
Am GETAC **Windows PowerShell 5.1 als Administrator** öffnen und in den Projektordner `Stagging` wechseln. Den vorgesehenen Netzwerkanschluss mit dem separaten Installations-Switch verbinden; kein produktives DHCP-Netz verwenden.
|
||||
|
||||
```powershell
|
||||
.\Setup-StagingServer.ps1
|
||||
```
|
||||
|
||||
Dieser Aufruf liest Excel und prüft Windows, Adapter, Adressen und vorhandenes DHCP, ohne Änderungen vorzunehmen. Ein anderer Workbook-Pfad ist mit `-Workbook 'C:\Pfad\ConfigWorkbook_KIS.xlsx'` möglich.
|
||||
|
||||
Voraussetzung ist ein eigenständiger Windows Server ohne Domänenmitgliedschaft. Vorhandene fremde DHCP-Bereiche und DHCP-Optionen werden abgewiesen. Die Windows-Rollendateien und der Netzwerktreiber müssen verfügbar sein. Das Skript ändert keine Ausführungsrichtlinie; vorgeschriebene Skriptsignaturen sind nach dem Verfahren der Organisation bereitzustellen.
|
||||
|
||||
## 3. Einrichten
|
||||
|
||||
```powershell
|
||||
.\Setup-StagingServer.ps1 -Apply
|
||||
```
|
||||
|
||||
Nach der angezeigten Übersicht `EINRICHTEN` eingeben. Das Skript:
|
||||
|
||||
- installiert DHCP mit Verwaltungswerkzeugen;
|
||||
- setzt die feste IP aus Excel, ohne Gateway hinzuzufügen;
|
||||
- schaltet die DNS-Registrierung des Installationsadapters aus;
|
||||
- erstellt einen zunächst **inaktiven** DHCP-Bereich mit vier Stunden Lease-Dauer;
|
||||
- bindet DHCPv4 ausschließlich an den ausgewählten Adapter und deaktiviert DHCPv6-Bindungen;
|
||||
- ergänzt eine Firewall-Freigabe für DHCP am Installationsadapter;
|
||||
- erstellt den Medienordner und auf demselben Laufwerk `Staging-PXE\Boot`.
|
||||
|
||||
Andere Adapter behalten ihre IP-Konfiguration; ihre DHCP-Server-Bindungen werden deaktiviert. Es werden keine Router-, DNS- oder PXE-Optionen und keine Freigaben angelegt. DHCP allein macht das GETAC nicht zum Router oder DNS-Server. Passwörter werden in diesem Schritt nicht benötigt; das Skript läuft mit dem angemeldeten Administratorkonto.
|
||||
|
||||
## 4. DHCP bei Bedarf aktivieren
|
||||
|
||||
```powershell
|
||||
.\Setup-StagingServer.ps1 -Apply -ActivateDhcp
|
||||
```
|
||||
|
||||
Nach erneuter Prüfung und Bestätigung vergibt DHCP im Installationsnetz Adressen. Ein erneuter Lauf mit nur `-Apply` setzt den Bereich wieder inaktiv. Bei unveränderter Excel werden die eigene feste IP und der eigene DHCP-Bereich wiederverwendet. Abweichende bestehende Bereiche werden nicht automatisch ersetzt.
|
||||
|
||||
**Danach sind IP-Vergabe und Windows-Grundvorbereitung eingerichtet. Ein Zielserver kann noch keinen PVE-/ESXi-Installer per PXE laden.**
|
||||
|
||||
## Protokoll und Fehler
|
||||
|
||||
Vor Änderungen speichert das Skript den erfassten Ausgangszustand und den Plan unter `runs/windows-setup/run-...`. Bei Erfolg kommt `result.json` hinzu. Dieser Ordner ist aus Git ausgeschlossen. Die JSON-Dateien dienen zur manuellen Wiederherstellung, sind kein vollständiges Windows-Backup und enthalten keine Passwörter.
|
||||
|
||||
Bei Fehlern während der Einrichtung wird der DHCP-Dienst gestoppt und ein bereits bearbeiteter Bereich möglichst deaktiviert. Bereits gesetzte IP-Adressen, Verzeichnisse und installierte Rollen werden nicht automatisch zurückgesetzt. Deshalb lokal am GETAC arbeiten. Falls die Rolleninstallation einen Neustart verlangt, lokal neu starten und erneut prüfen.
|
||||
|
||||
Ist DHCP nach einem Fehler installiert, aber gestoppt, schlägt die nächste Bestandsprüfung beim Lesen der DHCP-Konfiguration fehl. Ursache anhand der Fehlermeldung beheben, den GETAC am isolierten Installationsnetz belassen und den Dienst vor einer erneuten Prüfung mit `Start-Service DHCPServer` starten. Dieser manuelle Start kann vorhandene aktive Bereiche wieder bedienen.
|
||||
|
||||
## Prüfung und Quellen
|
||||
|
||||
46 automatisierte Prüfungen unter PowerShell 7.4.1 auf macOS prüfen Eingaben, Konflikte, Wiederholung, Aktivierung und Fehlerbehandlung. Windows-Verwaltungsbefehle werden dabei simuliert. Ein Test unter Windows PowerShell 5.1 auf dem tatsächlichen GETAC einschließlich DHCP-Lease und Firewall ist noch erforderlich.
|
||||
|
||||
Die verwendeten Windows-Verwaltungsbefehle sind bei Microsoft beschrieben: [DHCP bereitstellen](https://learn.microsoft.com/en-us/windows-server/networking/technologies/dhcp/dhcp-deploy-wps), [IPv4-Bindungen](https://learn.microsoft.com/en-us/powershell/module/dhcpserver/set-dhcpserverv4binding?view=windowsserver2025-ps), [IPv6-Bindungen](https://learn.microsoft.com/en-us/powershell/module/dhcpserver/set-dhcpserverv6binding?view=windowsserver2025-ps).
|
||||
Reference in New Issue
Block a user