diff --git a/Windows/ZabbixAgent/CheckAndStartZabbixAgent2.ps1 b/Windows/ZabbixAgent/CheckAndStartZabbixAgent2.ps1 new file mode 100644 index 0000000000000000000000000000000000000000..153486b4a3ccc6bdaf852a1b526fbc6b46f902ff --- /dev/null +++ b/Windows/ZabbixAgent/CheckAndStartZabbixAgent2.ps1 @@ -0,0 +1,34 @@ +# Retrieve the domain name dynamically +$domainName = (Get-CimInstance -ClassName Win32_ComputerSystem).Domain + +# Path to the custom configuration file on SYSVOL using the dynamic domain name +$customConfigPath = "\\$domainName\SYSVOL\$domainName\scripts\zabbix_agent2.conf" + +# Path to the Zabbix Agent 2 configuration file +$agentConfigPath = "C:\Program Files\Zabbix Agent 2\zabbix_agent2.conf" + +# Function to check if the Zabbix Agent 2 service is running +function Check-ZabbixAgent2 { + $service = Get-Service -Name "Zabbix Agent 2" -ErrorAction SilentlyContinue + if ($service -and $service.Status -eq 'Running') { + Write-Output "Zabbix Agent 2 is running." + return $true + } else { + Write-Output "Zabbix Agent 2 is not running." + return $false + } +} + +# Function to copy the custom configuration file and start the service +function Start-ZabbixAgent2 { + Write-Output "Copying custom configuration file..." + Copy-Item -Path $customConfigPath -Destination $agentConfigPath -Force + + Write-Output "Starting Zabbix Agent 2 service..." + Start-Service -Name "Zabbix Agent 2" +} + +# Main script logic +if (-not (Check-ZabbixAgent2)) { + Start-ZabbixAgent2 +} \ No newline at end of file