ftsr 发表于 2018-9-2 11:06:14

Powershell 自动化安装zabbix agent

############################################  
#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($ZipFile,$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)
  
$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


页: [1]
查看完整版本: Powershell 自动化安装zabbix agent