AftabHussain

Download and Install Nagios NSClient

Sep 11th, 2015
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
  2. $myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
  3. $adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
  4. if (-not $myWindowsPrincipal.IsInRole($adminRole))
  5. {
  6.     $newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
  7.     $newProcess.Arguments = $myInvocation.MyCommand.Definition;
  8.     $newProcess.Verb = "runas";
  9.     [System.Diagnostics.Process]::Start($newProcess);
  10.     exit
  11. }
  12.  
  13. New-Item C:\Windows\Temp\nagios
  14. ## Server 2008 Compatibility, hence .Net.
  15. "Downloading NSClient"
  16. $downloader = new-object System.Net.WebClient
  17. $downloader.Proxy.Credentials=[System.Net.CredentialCache]::DefaultNetworkCredentials;
  18. $downloader.DownloadFile('http://<P-Address>/nsclient.ini.txt','C:\Windows\Temp\nagios\nsclient.ini')
  19.  
  20. If ($ENV:PROCESSOR_ARCHITECTURE -eq 'x86') {
  21.     $downloader.DownloadFile('http://<IP-Address>/NSCP-0.4.3.143-Win32.msi','C:\Windows\Temp\nagios\NSCP-0.4.3.143-Win32.msi')
  22.     Start-Process -FilePath msiexec -ArgumentList /i, C:\Windows\Temp\nagios\NSCP-0.4.3.143-Win32.msi, /passive, /norestart, ADDLOCAL='ALL', REMOVE='Documentation,NSCAPlugin' -Wait
  23. }
  24. Else {
  25.     $downloader.DownloadFile('http://<IP-Address>/NSCP-0.4.1.105-x64.msi','C:\Windows\Temp\nagios\NSCP-0.4.1.105-x64.msi')
  26.     Start-Process -FilePath msiexec -ArgumentList /i, C:\Windows\Temp\nagios\NSCP-0.4.1.105-x64.msi, /passive, /norestart, ADDLOCAL='ALL', REMOVE='Documentation,NSCAPlugin' -Wait
  27. }
  28.  
  29. Copy-Item -Path 'C:\Windows\Temp\nagios\nsclient.ini' -Destination 'C:\Program Files\NSClient++\nsclient.ini' -Force
  30. Restart-Service nscp
  31. Remote-Item C:\Windows\Temp\nagios -Recurse -Force
Advertisement
Add Comment
Please, Sign In to add comment