SHARE
TWEET

Untitled

a guest May 23rd, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $os_name = (Get-WmiObject -Class Win32_OperatingSystem).CSName
  2. $os_ver = (Get-WmiObject -Class Win32_OperatingSystem).OSArchitecture
  3. #1 - PC, 2 - DC, 3 - server
  4. $os_type =  (Get-WmiObject -Class Win32_OperatingSystem).ProductType
  5. ### Settings ###
  6. $agents_store = "\\srv\folder\zabbix_agents"
  7. $zabbix_server = "IP ZABBIX Server"
  8. $install_log="\\srv\folder\zabbix_agents\install_logs\$os_name.log"
  9. #################
  10.  
  11. Add-Content -Path $install_log -Value "$(Get-Date)"
  12. Add-Content -Path $install_log -Value "$os_name"
  13.  
  14. try { New-Item -ItemType Directory -Path "C:\zabbix" -ErrorAction Stop | Out-Null
  15.       switch ($ver) {
  16.           {$os_ver -like "32*"} { Copy-Item -Path "$agents_store\x86\bin\zabbix_agentd.exe" -Destination "C:\zabbix" -Recurse
  17.                                   Add-Content -Path $install_log -Value "Zabbix Agent x86" }
  18.           {$os_ver -like "64*"} { Copy-Item -Path "$agents_store\x64\bin\zabbix_agentd.exe" -Destination "C:\zabbix" -Recurse
  19.                                   Add-Content -Path $install_log -Value "Zabbix Agent x64"}}
  20. }
  21. catch [System.Management.Automation.ActionPreferenceStopException] {
  22.       Add-Content -Path $install_log -Value $Error[0]
  23. }
  24.  
  25. try { New-Item -ItemType File -Path "C:\zabbix\zabbix_agentd.conf" -ErrorAction Stop | Out-Null
  26. Add-Content -Path "C:\zabbix\zabbix_agentd.conf" -Value "Hostname=$os_name"
  27.       Add-Content -Path "C:\zabbix\zabbix_agentd.conf" -Value "Server=$zabbix_server"
  28.       Add-Content -Path "C:\zabbix\zabbix_agentd.conf" -Value "ServerActive=$zabbix_server"
  29.       Add-Content -Path "C:\zabbix\zabbix_agentd.conf" -Value "HostMetadataItem=$os_type"
  30.       Add-Content -Path "C:\zabbix\zabbix_agentd.conf" -Value "EnableRemoteCommands=1"
  31.       Add-Content -Path "C:\zabbix\zabbix_agentd.conf" -Value "LogRemoteCommands=1"
  32.       Add-Content -Path "C:\zabbix\zabbix_agentd.conf" -Value "LogFile=C:\zabbix\zabbix_agentd.log"      
  33.       Add-Content -Path $install_log -Value "Создан файл конфигурации для сервера $zabbix_server"
  34. }
  35. catch [System.Management.Automation.ActionPreferenceStopException] {
  36.       Add-Content -Path $install_log -Value $Error[0]      
  37. }
  38.  
  39. switch ($q_exist=!(Get-Service -Name 'Zabbix Agent' -ErrorAction SilentlyContinue)) {
  40.     {$q_exist -like "True"} { Start-Process -WorkingDirectory "$env:windir" -FilePath "cmd.exe" -ArgumentList "/c c:\zabbix\zabbix_agentd.exe -c c:\zabbix\zabbix_agentd.conf -i" -Verb runas
  41.                               Add-Content -Path $install_log -Value "Zabbix Agent installed." }
  42.     {$q_exist -like "False"} { Add-Content -Path $install_log -Value "Service Zabbix agent already installed." }
  43. }
  44.  
  45. Start-Sleep 5
  46.  
  47. switch ($q_status=(Get-Service -Name "Zabbix Agent").Status) {
  48.     {$q_status -eq "Running"} { Add-Content -Path $install_log -Value "Serivce Zabbix Agent already is running." }
  49.     {$q_status -eq "Stopped"} { Start-Process -WorkingDirectory "$PSHOME" -FilePath "powershell.exe" -ArgumentList "Start-Service -Name 'Zabbix Agent'" -Verb runas
  50.                                 Add-Content -Path $install_log -Value "Zabbix Agent Service is started." }
  51. }
  52.  
  53. switch ($f_rule=!(netsh advfirewall firewall show rule name="All" | findstr "zabbix_agent_passive_in")) {
  54.     {$f_rule -like "True"} { Start-Process -WorkingDirectory "$env:windir" -FilePath "cmd.exe" -ArgumentList '/c netsh advfirewall firewall add rule name="zabbix_agent_passive_in" dir=in protocol=TCP profile=Domain,Private localport=10050 action=allow enable=yes' -Verb runas
  55.                              Add-Content -Path $install_log -Value "Add firewall rule zabbix_agent_passive_in." }
  56.     {$f_rule -like "False"} { Add-Content -Path $install_log -Value "Firewall rule zabbix_agent_passive_in already exist." }
  57. }
  58.  
  59. Add-Content -Path $install_log -Value "###config###"
  60. Add-Content -Path $install_log -Value "$(Get-Content "C:\zabbix\zabbix_agentd.conf")"
  61. Add-Content -Path $install_log -Value "############"
  62.  
  63. Start-Sleep 5
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top