# encoding: ascii
# api: powershell
# title: Enable/Configure SNMP
# description: Enables SNMP via Add-WindowsFeature (If not already enabled)
# version: 0.1
# type: script
# author: 8i5i9
# license: CC0
# x-poshcode-id: 4225
# x-archived: 2015-05-09T14:45:24
# x-published: 2015-06-25T18:15:00
#
# Configures SNMP Settings via reg add calls (Warning this will overwrite current settings)
# (extra lines removed that appeared to have been from a paste twice)
#
#Powershell Script To Install SNMP Services (SNMP Service, SNMP WMI Provider)
#Variables :)
$pmanagers = "ADD YOUR MANAGER(s)"
$commstring = "ADD YOUR COMM STRING"
#Import ServerManger Module
Import-Module ServerManager
#Check If SNMP Services Are Already Installed
$check = Get-WindowsFeature | Where-Object {$_.Name -eq "SNMP-Services"}
If ($check.Installed -ne "True") {
#Install/Enable SNMP Services
Add-WindowsFeature SNMP-Services | Out-Null
}
##Verify Windows Servcies Are Enabled
If ($check.Installed -eq "True"){
#Set SNMP Permitted Manager(s) ** WARNING : This will over write current settings **
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers" /v 1 /f /t REG_SZ /d localhost | Out-Null
#Used as counter for incremting permitted managers
$i = 2
Foreach ($manager in $pmanagers){
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers" /v $i /f /t REG_SZ /d $manager | Out-Null
$i++
}
#Set SNMP Community String(s)- *Read Only*
Foreach ( $string in $commstring){
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\ValidCommunities" /v $string /f /t REG_DWORD /d 4 | Out-Null
}
}
Else {Write-Host "Error: SNMP Services Not Installed"}