Advertisement
stephanlinke

Install SNMP on Windows Servers automatically

May 3rd, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ####################################
  2.  # Script Location: T:\scripts\InstallSNMP.ps1
  3.  # Description: Powershell script to install and configure SNMP Services (SNMP Service, SNMP WMI Provider)
  4.  # Last update: 2014/02/14
  5.  ####################################
  6.  
  7.  #Variables :)
  8.  $pmanagers = @("") # ADD YOUR MANAGER(s) in format @("manager1","manager2")
  9.  $CommString = @("") # ADD YOUR COMM STRING(s) in format @("Community1","Community2")
  10.  
  11.  #Import ServerManger Module
  12.  Import-Module ServerManager
  13.  
  14.  #Check if SNMP-Service is already installed
  15.  $check = Get-WindowsFeature -Name SNMP-Service
  16.  
  17.  If ($check.Installed -ne "True") {
  18.      #Install/Enable SNMP-Service
  19.      Write-Host "SNMP Service Installing..."
  20.      Get-WindowsFeature -name SNMP* | Add-WindowsFeature -IncludeManagementTools | Out-Null
  21.  }
  22.  
  23.  $check = Get-WindowsFeature -Name SNMP-Service
  24.  
  25.  ##Verify Windows Services Are Enabled
  26.  If ($check.Installed -eq "True"){
  27.      Write-Host "Configuring SNMP Services..."
  28.      #Set SNMP Permitted Manager(s) ** WARNING : This will over write current settings **
  29.      reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers" /v 1 /t REG_SZ /d localhost /f | Out-Null
  30.  
  31.      #Set SNMP Traps and SNMP Community String(s) - *Read Only*
  32.      Foreach ($String in $CommString){
  33.          reg add ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\" + $String) /f | Out-Null
  34.          # Set the Default value to be null
  35.          reg delete ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\" + $String) /ve /f | Out-Null
  36.          reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\ValidCommunities" /v $String /t REG_DWORD /d 4 /f | Out-Null
  37.          $i = 2
  38.          Foreach ($Manager in $PManagers){
  39.              reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers" /v $i /t REG_SZ /d $manager /f | Out-Null
  40.              reg add ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\" + $String) /v $i /t REG_SZ /d $manager /f | Out-Null
  41.              $i++
  42.          }
  43.      }
  44.  }
  45.  Else
  46.  { Write-Host "Error: SNMP Services Not Installed" }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement