This PowerShell script is designed to run as a scheduled task on servers and keep the Zabbix Agent installation up to date automatically. The task is triggered through a GPO, so each server checks its local installation source on its own and updates itself when a newer version is available. This makes the deployment process simple, scalable, and low-maintenance across many servers.
The script also handles the first installation case. If no Zabbix Agent is installed yet, the script installs it automatically from the files available in the local install directory. If an older version is already present, the script stops the service, removes the old agent, copies the updated files, installs the new version, and starts the service again.
How it works
The script first compares the version of the Zabbix Agent in the source folder with the version currently installed on the server. If a newer version is found, it performs an update. If no agent is installed at all, it performs a fresh installation. If the installed version is already current, no changes are made.
This approach is especially useful in environments where Zabbix agents are staged centrally and then maintained locally by a scheduled task. It removes the need for manual updates and ensures that servers stay aligned with the version stored in the installation repository.
Configuration handling
The script also checks whether the Zabbix configuration file already exists. If a valid configuration file is present, it is left untouched. If no configuration file is found, the script uses the Zabbix default logic and creates the active configuration file from the default file. This ensures that the original configuration is not overwritten and that a new config is only created when none exists yet.
Variable overview
| Variable | Purpose |
|---|---|
ZbxSrcPath | Base source path that contains the Zabbix installation files. |
ZbxLogDir | Directory used for transcript and log output. |
ZbxLogFile | Full path to the transcript log file. |
ZbxAgentSrcPath | Source folder that contains the Zabbix agent package. |
ZbxAgentSrcExe | Path to the source Zabbix Agent executable used for version detection. |
ZbxConfigFile | Path to the active Zabbix configuration file on the local system. |
ZbxDefaultConfigFile | Path to the default configuration file used when no active config exists. |
ZbxAgentDstPath | Local destination path where the agent files are copied. |
ZbxAgentExePath | Path to the locally installed Zabbix Agent executable. |
ZbxAgentConfPath | Path to the local Zabbix Agent configuration file. |
ZbxAgentService | Windows service name used to stop, uninstall, install, and start the agent. |
GitHub download
Download the script here: GitHub repository