#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/NetworkServices.psm1') -Force -DisableNameChecking $plan=Get-NetworkServicesPlan (Read-KisWorkbook $Workbook) Write-Host "Staging $version - Schritt 02: DNS und DHCP-Reservierungen" Write-Host "DNS-Zone: $($plan.Zone), DNS-IP: $($plan.Base.IP)" $plan.Records | Format-Table | Out-Host $plan.Reservations | Format-Table | Out-Host if ([Environment]::OSVersion.Platform -ne [PlatformID]::Win32NT) { if ($Apply) { throw 'Einrichtung nur lokal auf dem GETAC unter Windows Server.' } Write-Host 'Nur Excel-Plan geprueft. Windows-Bestand wird auf dem GETAC geprueft.'; return } if ($PSVersionTable.PSEdition -ne 'Desktop') { throw 'Windows PowerShell 5.1 verwenden.' } $principal=New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { throw 'Windows PowerShell lokal als Administrator starten.' } Import-Module ServerManager Import-Module DhcpServer $state=Get-NetworkServicesState $plan Assert-NetworkServicesState $plan $state if (-not $Apply) { Write-Host 'Vorschau ohne Aenderungen beendet. Einrichten mit -Apply.'; return } Write-Host 'Nur im separaten Installationsnetz: DNS-Rolle, lokale Zone und Reservierungen werden eingerichtet. Externe DNS-Aufloesung bleibt deaktiviert.' Write-Host 'DHCP wird waehrend der Einrichtung inaktiv. -ActivateDhcp aktiviert ihn erst nach erfolgreicher Pruefung.' if ((Read-Host 'Zum Einrichten EINRICHTEN eingeben') -cne 'EINRICHTEN') { Write-Host 'Abgebrochen.'; return } $backup=New-PrivateRunDirectory (Join-Path $PSScriptRoot 'runs/network-services') $encoding=New-Object Text.UTF8Encoding($false) [IO.File]::WriteAllText((Join-Path $backup 'before.json'),($state | ConvertTo-Json -Depth 10),$encoding) [IO.File]::WriteAllText((Join-Path $backup 'plan.json'),($plan | ConvertTo-Json -Depth 6),$encoding) try { $result=Invoke-NetworkServices $plan $state -ActivateDhcp:$ActivateDhcp [IO.File]::WriteAllText((Join-Path $backup 'result.json'),($result | ConvertTo-Json),$encoding) $result | Format-List | Out-Host Write-Host "Schritt 02 abgeschlossen. Ergebnis: $backup. PXE-Bootdienst ist noch nicht eingerichtet." } catch { Write-Host "Schritt 02 unvollstaendig. Ausgangszustand: $backup. Bereits angelegte Eintraege bleiben zur Pruefung erhalten." throw }