From d43f4b8f3564205480fe44c9de76182563cfb31c Mon Sep 17 00:00:00 2001
From: Andreas Lindemark <andreas.lindemark@liu.se>
Date: Thu, 3 Apr 2025 19:51:41 +0200
Subject: [PATCH] Added some error handling in the one-liner script to install
 and configure a scheduled task fro `CheckAndStartZabbixAgent2.ps1`.

---
 Windows/ZabbixAgent/README.md | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Windows/ZabbixAgent/README.md b/Windows/ZabbixAgent/README.md
index d2b1123..c14563e 100644
--- a/Windows/ZabbixAgent/README.md
+++ b/Windows/ZabbixAgent/README.md
@@ -30,7 +30,8 @@ This one-liner download and install does the following:
 To download, save, and execute the script, you need to temporarily change the PowerShell execution policy to allow script execution. You can do all this by using the following one-liner code in an elevated PowerShell session:
 
 ```powershell
-Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force; Stop-Service -Name "Zabbix Agent 2"; $scriptPath = "C:\Windows\System32\Tasks\CheckAndStartZabbixAgent2.ps1"; Invoke-WebRequest -Uri "https://gitlab.liu.se/andli86/snippets/-/raw/master/Windows/ZabbixAgent/CheckAndStartZabbixAgent2.ps1" -OutFile $scriptPath; schtasks /create /tn "CheckAndStartZabbixAgent2" /tr "powershell.exe -File $scriptPath" /sc hourly /mo 3 /ru SYSTEM; schtasks /run /tn "CheckAndStartZabbixAgent2";
+Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force; Stop-Service -Name "Zabbix Agent 2"; $scriptPath = "C:\Windows\System32\Tasks\CheckAndStartZabbixAgent2.ps1"; try { Invoke-WebRequest -Uri "https://gitlab.liu.se/andli86/snippets/-/raw/master/Windows/ZabbixAgent/CheckAndStartZabbixAgent2.ps1" -OutFile $scriptPath -ErrorAction Stop; schtasks /create /tn "CheckAndStartZabbixAgent2" /tr "powershell.exe -File $scriptPath" /sc hourly /mo 3 /ru SYSTEM; schtasks /run /tn "CheckAndStartZabbixAgent2"; } catch { Write-Output "Failed to download the script file. Exiting prematurely."; Start-Service -Name "Zabbix Agent 2"; exit 1; }
+
 ```
 
 ### Manual Installation
-- 
GitLab