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

Modified the script to give more output and changed the $customConfigPath

parent d88dfb2f
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@ $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."
......@@ -19,16 +20,32 @@ function Test-ZabbixAgent2 {
}
}
# 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
# Function to copy the custom configuration file
function Copy-ZabbixConfig {
Write-Output "Copying custom configuration file from $customConfigPath to $agentConfigPath..."
try {
Copy-Item -Path $customConfigPath -Destination $agentConfigPath -Force
Write-Output "Configuration file copied successfully."
} catch {
Write-Output "Failed to copy configuration file: $_"
}
}
# Function to start the Zabbix Agent 2 service
function Start-ZabbixAgent2 {
Write-Output "Starting Zabbix Agent 2 service..."
Start-Service -Name "Zabbix Agent 2"
try {
Start-Service -Name "Zabbix Agent 2"
Write-Output "Zabbix Agent 2 service started successfully."
} catch {
Write-Output "Failed to start Zabbix Agent 2 service: $_"
}
}
# Main script logic
if (-not (Test-ZabbixAgent2)) {
Copy-ZabbixConfig
Start-ZabbixAgent2
} else {
Write-Output "Zabbix Agent 2 is already running. No action needed."
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment