feat(stagging): prepare Windows staging server in version 0.2.0
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user