PoshCode Logo PowerShell Code Repository

Enable/Configure SNMP by St3v3o 4 years ago
View followups from 8i5i9, plamen, public, Diamantis Dimitr and suporte | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/2066"></script>download | new post

Enables SNMP via Add-WindowsFeature (If not already enabled)
Configures SNMP Settings via reg add calls (Warning this will overwrite current settings)

  1. #Powershell Script To Install SNMP Services (SNMP Service, SNMP WMI Provider)
  2.  
  3. #Variables :)
  4. $pmanagers = "ADD YOUR MANAGER(s)"
  5. $commstring = "ADD YOUR COMM STRING"
  6.  
  7. #Import ServerManger Module
  8. Import-Module ServerManager
  9.  
  10. #Check If SNMP Services Are Already Installed
  11. $check = Get-WindowsFeature | Where-Object {$_.Name -eq "SNMP-Services"}
  12. If ($check.Installed -ne "True") {
  13.         #Install/Enable SNMP Services
  14.         Add-WindowsFeature SNMP-Services | Out-Null
  15. }
  16.  
  17. ##Verify Windows Servcies Are Enabled
  18. If ($check.Installed -eq "True"){
  19.         #Set SNMP Permitted Manager(s) ** WARNING : This will over write current settings **
  20.         reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers" /v 1 /t REG_SZ /d localhost /f | Out-Null
  21.         #Used as counter for incremting permitted managers
  22.         $i = 2
  23.         Foreach ($manager in $pmanagers){
  24.                 reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers" /v $i /t REG_SZ /d $manager /f | Out-Null
  25.                 $i++
  26.                 }
  27.         #Set SNMP Community String(s)- *Read Only*
  28.         Foreach ( $string in $commstring){
  29.                 reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\ValidCommunities" /v $string /t REG_DWORD /d 4 /f | Out-Null
  30.                 }
  31. }
  32. Else {Write-Host "Error: SNMP Services Not Installed"}

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me