From 54bcd255538c5ba053def90fd3d61104f078fb97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0t=C4=9Bp=C3=A1n?= Date: Tue, 21 Jul 2026 18:29:52 +0200 Subject: [PATCH] Update Download-WinRMConfigScript.ps1 to version 1.2.0, modifying exit behavior to prevent closing the PowerShell window when run via "irm | iex". --- .../Download-WinRMConfigScript.ps1 | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ConfigWinRMForZabbix/Download-WinRMConfigScript.ps1 b/ConfigWinRMForZabbix/Download-WinRMConfigScript.ps1 index bde669e..0f5febd 100644 --- a/ConfigWinRMForZabbix/Download-WinRMConfigScript.ps1 +++ b/ConfigWinRMForZabbix/Download-WinRMConfigScript.ps1 @@ -36,11 +36,13 @@ .NOTES Author: Petr Štěpán Created: 2026-07-21 - Version: 1.1.0 + Version: 1.2.0 Changelog: 1.0.0 - Initial version 1.1.0 - Added $env:ZabbixProxyIPAddress fallback so a plain "irm | iex" one-liner can supply the IP address without "& { ... } -Param" wrapping + 1.2.0 - Only call exit when running as a real .ps1 file, not when run via + "irm | iex" - exit would otherwise close the caller's PowerShell window #> [CmdletBinding()] @@ -181,7 +183,16 @@ try { } catch { Write-Error "Script failed: $_" - exit 1 + # $MyInvocation.MyCommand.Path is only set when this runs as an actual .ps1 file. + # When run via "irm | iex" there is no backing file - the code executes in + # the caller's own session, so calling exit here would close their whole + # PowerShell window instead of just ending this script. + if ($MyInvocation.MyCommand.Path) { + exit 1 + } + return } -exit 0 +if ($MyInvocation.MyCommand.Path) { + exit 0 +}