Advertisement
stephanlinke

SNMP Network Installer

Sep 8th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ####################################
  2. # Last update: 20150310pra
  3. # Description: Powershell script to install and configure SNMP Services on Windows 2008R2, 2012 and 2012R2 Server (SNMP Service, SNMP WMI Provider)
  4. # start As Administrator with C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -Command "&{ \\Servername\InstallSNMP\installsnmp.ps1}"
  5. # Script Location: \\Servername\InstallSNMP\installsnmp.ps1
  6. ####################################
  7.  
  8. #Variables :)
  9. $PManagers = @("172.29.60.206") # ADD YOUR MANAGER(s) in format @("manager1","manager2")
  10. $CommString = @("public") # ADD YOUR COMM STRING(s) in format @("Community1","Community2")
  11.  
  12. #Import ServerManger Module
  13. Import-Module ServerManager
  14.  
  15. #Check if SNMP-Service is already installed
  16. $check = Get-WindowsFeature -Name SNMP-Service
  17.  
  18. If ($check.Installed -ne "True")
  19.     {
  20.     #Install/Enable SNMP-Service
  21.     Write-Host "SNMP Service Installing..."
  22.     # Get OS Version to use the right install command
  23.     [int]$verMajor = [environment]::OSVersion.Version | ft -property Major -HideTableHeaders -auto | Out-String
  24.     [int]$verMinor = [environment]::OSVersion.Version | ft -property Minor -HideTableHeaders -auto | Out-String
  25.     if ($verMajor -eq 6)
  26.         {
  27.         $winVer = switch ($verMinor)
  28.             {
  29.             0 {"Win2008"}
  30.             1 {"Win2008R2"}
  31.             2 {"Win2012"}
  32.             3 {"Win2012R2"}
  33.             }
  34.         }
  35.     #Install SNMP on 2008 (R2)
  36.     if ($winVer -eq "Win2008" -or $winVer -eq "Win2008R2")
  37.         {
  38.         Get-WindowsFeature -name SNMP* | Add-WindowsFeature | Out-Null
  39.         }
  40.     #Install SNMP on 20012 (R2)
  41.     if ($winVer -eq "Win2012" -or $winVer -eq "Win2012R2")
  42.         {
  43.         Get-WindowsFeature -name SNMP* | Add-WindowsFeature -IncludeManagementTools | Out-Null
  44.         }
  45.     }
  46.  
  47. $check = Get-WindowsFeature -Name SNMP-Service
  48.  
  49. ##Verify Windows Services Are Enabled
  50. If ($check.Installed -eq "True")
  51.     {
  52.     Write-Host "Configuring SNMP Services..."
  53.     #Set SNMP Permitted Manager(s) ** WARNING : This will over write current settings **
  54.     reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers" /v 1 /t REG_SZ /d localhost /f | Out-Null
  55.  
  56.     #Set SNMP Traps and SNMP Community String(s) - *Read Only*
  57.     Foreach ($String in $CommString)
  58.         {
  59.         reg add ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\" + $String) /f | Out-Null
  60.         # Set the Default value to be null
  61.         reg delete ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\" + $String) /ve /f | Out-Null
  62.         reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\ValidCommunities" /v $String /t REG_DWORD /d 4 /f | Out-Null
  63.         $i = 2
  64.         Foreach ($Manager in $PManagers)
  65.             {
  66.             reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers" /v $i /t REG_SZ /d $manager /f | Out-Null
  67.             reg add ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\" + $String) /v $i /t REG_SZ /d $manager /f | Out-Null
  68.             $i++
  69.             }
  70.         }
  71.     }
  72. Else
  73.     {
  74.     Write-Host "Error: SNMP Services Not Installed"
  75.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement