Update Download-WinRMConfigScript.ps1 to version 1.2.0, modifying exit behavior to prevent closing the PowerShell window when run via "irm | iex".

This commit is contained in:
Petr Štěpán
2026-07-21 18:29:52 +02:00
parent fcf3bb39fc
commit 54bcd25553
@@ -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: $_"
# $MyInvocation.MyCommand.Path is only set when this runs as an actual .ps1 file.
# When run via "irm <url> | 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
}
if ($MyInvocation.MyCommand.Path) {
exit 0
}