param( [Parameter(Mandatory = $true)] [string]$SourcePath, [Parameter(Mandatory = $true)] [string]$InstallPath, [string]$EventSource = "BizTalkMonitorConfigGenerator", [string]$EventLogName = "Application", [switch]$RegisterEventSource, [switch]$CreateBackup ) Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' function Write-Info { param([string]$Message) Write-Host "[INFO] $Message" } if (-not (Test-Path -LiteralPath $SourcePath)) { throw "SourcePath '$SourcePath' existiert nicht." } $sourceFullPath = (Resolve-Path -LiteralPath $SourcePath).Path $installFullPath = [System.IO.Path]::GetFullPath($InstallPath) Write-Info "Quelldateien: $sourceFullPath" Write-Info "Zielverzeichnis: $installFullPath" if (Test-Path -LiteralPath $installFullPath) { if ($CreateBackup) { $backupRoot = Join-Path -Path ([System.IO.Path]::GetDirectoryName($installFullPath)) -ChildPath ((Split-Path -Path $installFullPath -Leaf) + '_backup_' + (Get-Date -Format 'yyyyMMdd_HHmmss')) Write-Info "Erstelle Backup unter $backupRoot" Copy-Item -Path (Join-Path $installFullPath '*') -Destination $backupRoot -Recurse -Force -ErrorAction SilentlyContinue } } else { New-Item -Path $installFullPath -ItemType Directory | Out-Null } Write-Info "Kopiere Dateien..." Copy-Item -Path (Join-Path $sourceFullPath '*') -Destination $installFullPath -Recurse -Force New-Item -Path (Join-Path $installFullPath 'logs') -ItemType Directory -Force | Out-Null if ($RegisterEventSource) { $registerScript = Join-Path -Path $PSScriptRoot -ChildPath 'register-event-source.ps1' if (-not (Test-Path -LiteralPath $registerScript)) { throw "register-event-source.ps1 wurde nicht gefunden: $registerScript" } Write-Info "Registriere Event Source '$EventSource' im Log '$EventLogName'" & $registerScript -Source $EventSource -LogName $EventLogName } Write-Info 'Installation des BizTalkMonitorConfigGenerator abgeschlossen.' Write-Info 'Prüfen Sie nun generator-settings.json und führen Sie einen Testlauf aus.'