PoshCode Archive  Artifact [a5ef1f1fec]

Artifact a5ef1f1fecaf6651281e60b6e9e0a2238c4bf5af5b8478f6e2e8ff0e1d95d53d:

  • File Enable-Configure-SNMP.ps1 — part of check-in [8a598f3830] at 2018-06-10 13:51:48 on branch trunk — Enables SNMP via Add-WindowsFeature (If not already enabled) (user: Gabriel M size: 1724)

# encoding: ascii
# api: powershell
# title: Enable/Configure SNMP
# description: Enables SNMP via Add-WindowsFeature (If not already enabled)
# version: 0.1
# type: script
# author: Gabriel M
# license: CC0
# x-poshcode-id: 5198
# x-archived: 2014-06-02T05:47:32
# x-published: 2014-05-28T22:34:00
#
# Configures SNMP Settings via reg add calls (Warning this will overwrite current settings)
#
#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 /t REG_SZ /d localhost /f | 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 /t REG_SZ /d $manager /f | 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 /t REG_DWORD /d 4 /f | Out-Null
		}
}
Else {Write-Host "Error: SNMP Services Not Installed"}