diff --git a/wwwroot/remote.ps1 b/wwwroot/remote.ps1 index bdbb00d..58b908e 100644 --- a/wwwroot/remote.ps1 +++ b/wwwroot/remote.ps1 @@ -117,21 +117,41 @@ try { $stderr = "" try { - # EncodedCommand umgeht alle Quoting-Probleme (Anführungszeichen, Sonderzeichen) + # Process direkt starten um CLIXML-Parsing-Fehler bei stderr zu vermeiden $encodedCmd = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($command)) - $output = & powershell.exe -NoProfile -NonInteractive -EncodedCommand $encodedCmd 2>&1 - $stdoutLines = @($output | Where-Object { $_ -isnot [System.Management.Automation.ErrorRecord] }) - $stderrLines = @($output | Where-Object { $_ -is [System.Management.Automation.ErrorRecord] }) | - ForEach-Object { $_.ToString() } - $stdout = ($stdoutLines | Out-String).TrimEnd() - $stderr = ($stderrLines | Out-String).TrimEnd() - $exitCode = $LASTEXITCODE - if ($null -eq $exitCode) { $exitCode = 0 } + $proc = New-Object System.Diagnostics.Process + $proc.StartInfo.FileName = "powershell.exe" + $proc.StartInfo.Arguments = "-NoProfile -NonInteractive -EncodedCommand $encodedCmd" + $proc.StartInfo.RedirectStandardOutput = $true + $proc.StartInfo.RedirectStandardError = $true + $proc.StartInfo.UseShellExecute = $false + $proc.StartInfo.CreateNoWindow = $true + $proc.Start() | Out-Null + # stderr async lesen um Deadlocks zu vermeiden + $stderrTask = $proc.StandardError.ReadToEndAsync() + $stdout = $proc.StandardOutput.ReadToEnd() + $stderrTask.Wait() + $stderr = $stderrTask.Result + $proc.WaitForExit() + $exitCode = $proc.ExitCode + $proc.Dispose() } catch { $stderr = $_.Exception.Message $exitCode = 1 } + # CLIXML-Progress aus stderr filtern (PowerShell schreibt Modul-Lade-Fortschritt als CLIXML) + if ($stderr -and $stderr.StartsWith("#< CLIXML")) { + $cleanLines = @() + foreach ($line in ($stderr -split "`n")) { + $trimmed = $line.Trim() + if ($trimmed -eq "#< CLIXML") { continue } + if ($trimmed -match '^\.*\Completed\') { continue } + if ($trimmed -ne "") { $cleanLines += $line } + } + $stderr = ($cleanLines -join "`n").Trim() + } + # Ergebnis senden $response = @{ type = "result"