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

Finally got this script to work as I wanted it to work

parent 4e03397f
No related branches found
No related tags found
No related merge requests found
......@@ -9,20 +9,23 @@ $agentConfigPath = "C:\Program Files\Zabbix Agent 2\zabbix_agent2.conf"
# Function to test if the Zabbix Agent 2 service is running
function Test-ZabbixAgent2 {
Write-Output "Checking if Zabbix Agent 2 service is running..."
$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."
try {
$service = Get-Service -Name "Zabbix Agent 2" -ErrorAction Stop
if ($service.Status -eq 'Running') {
return $true
} else {
return $false
}
} catch {
return $false
}
}
# Function to copy the custom configuration file
function Copy-ZabbixConfig {
Write-Output "Copying custom configuration file from $customConfigPath to $agentConfigPath..."
Write-Output "Copying custom configuration file..."
Write-Output " - Source: $customConfigPath"
Write-Output " - Destination: $agentConfigPath"
try {
Copy-Item -Path $customConfigPath -Destination $agentConfigPath -Force
Write-Output "Configuration file copied successfully."
......@@ -43,7 +46,9 @@ function Start-ZabbixAgent2 {
}
# Main script logic
if (-not (Test-ZabbixAgent2)) {
$serviceRunning = Test-ZabbixAgent2
Write-Output "Service running status: $serviceRunning"
if (-not $serviceRunning) {
Copy-ZabbixConfig
Start-ZabbixAgent2
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment