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

New script CheckAndStartZabbixAgent2.ps1

parent b4aa9f24
No related branches found
No related tags found
No related merge requests found
# 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment