Skip to content
Snippets Groups Projects
Commit d43f4b8f authored by Andreas Lindemark's avatar Andreas Lindemark
Browse files

Added some error handling in the one-liner script to install and configure a...

Added some error handling in the one-liner script to install and configure a scheduled task fro `CheckAndStartZabbixAgent2.ps1`.
parent d3471287
Branches
No related tags found
No related merge requests found
...@@ -30,7 +30,8 @@ This one-liner download and install does the following: ...@@ -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: 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 ```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 ### Manual Installation
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment