Windows 2008 R2 Install SNMP Services via Powershell

I was looking for an easy installation and configuration for SNMP on a windows 2008 R2 server. After some goolging around I found the following script. I could be hard to find the script so that’s why I want to share it to other people.

Run your powershell console with administrator rights. Change only variable “ lines “ for the correct working. When you’ve changed these settings. you could copy / paste it to the powershell console.

#Powershell Script To Install SNMP Services (SNMP Service, SNMP WMI Provider)
 $pmanagers = "ADD HOST SNMP RECEIVER"
 $commstring = "ADD SNMP VALUENAME"
#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
 #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"}

After running the script for the first time you will see a warning that the SNMP services isn’t installed. you could correct his to re-run the script and than it will be configured / installed. I’ll try to find a powershell code for configuring all settings of the snmp-services


4 thoughts on “Windows 2008 R2 Install SNMP Services via Powershell

  1. Windows 7:

    Import-Module ServerManager

    Import-Module : The specified module ‘ServerManager’ was not loaded because no valid module file was found in any module directory.
    At line:1 char:14
    + Import-Module <<<< ServerManager
    + CategoryInfo : ResourceUnavailable: (ServerManager:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

    • Have your run this command in the administrative mode of powershell? Because I know that you get this error when you don’t doe that. And check if there are not HTML codes are copied to your computer.

  2. hey what value do i enter for
    $pmanagers = “ADD HOST SNMP RECEIVER”
    $commstring = “ADD SNMP VALUENAME”

    • First one is the server which is allowed to read the SNMP information

      Second one is the name you going to use for read out the the SNMP information.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s