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 +}