############################################ #Author:Lixiaosong #lixiaosong8706@gmail.com #For:Auto install zabbix-agent #Version:1.0 ############################################## wget http://www.zabbix.com/downloads/2.4.1/zabbix_agents_2.4.1.win.zip -OutFile C:\zabbix_agent.zip Function Unzip-File() { param([string]$ZipFile,[string]$TargetFolder) #確保目標文件夾必須存在 if(!(Test-Path $TargetFolder)) { mkdir $TargetFolder } $shellApp = New-Object -ComObject Shell.Application $files = $shellApp.NameSpace($ZipFile).Items() $shellApp.NameSpace($TargetFolder).CopyHere($files) } #將安裝文件解壓 Unzip-File -ZipFile C:\zabbix_agent.zip -TargetFolder C:\zabbix_agent #刪除默認配置文件 rm C:\zabbix_agent\conf\zabbix_agentd.win.conf $hostname=hostname Add-Content -value "LogFile=C:\zabbix_agent\zabbix.log" C:\zabbix_agent\conf\zabbix_agentd.win.conf Add-Content -value "Server=1.1.1.1" C:\zabbix_agent\conf\zabbix_agentd.win.conf Add-Content -value "Hostname=$hostname" C:\zabbix_agent\conf\zabbix_agentd.win.conf Add-Content -value "ServerActive=1.1.1.1" C:\zabbix_agent\conf\zabbix_agentd.win.conf #判斷系統類型 $sysinfo=(systeminfo.exe)[14] $sysinfonew=$sysinfo.Replace("系統類型: ","") if ($sysinfonew -like "x64-based PC" ){ C:\zabbix_agent\bin\win64\zabbix_agentd.exe -c C:\zabbix_agent\conf\zabbix_agentd.win.conf -i} else {C:\zabbix_agent\bin\win32\zabbix_agentd.exe -c C:\zabbix_agent\conf\zabbix_agentd.win.conf -i} Start-Service "Zabbix Agent" rm C:\zabbix_agent.zip