Enable SNMP for PRTG with PowerShell

, , ,

An MSP I do some consulting for use PRTG for their monitoring of environments. SNMP is a lightweight monitoring method for PRTG which trumps WMI monitoring. and doesn’t require admin rights on the local machine (or the shortcut of using a domain admin account). I’ve got a quick PowerShell script that will install the SNMP service in Windows and then configure the Community Name/String and IP Address for the server to be allowed. Simply load the script and change the variables at the top.

$CommunityManagers = '10.220.3.25'
$CommunityString = 'MySuperSecretSNMPCommunity'

You can then run the script which will install the SNMP service and configure it with the above values.

# Import the ServerManger Module
Import-Module ServerManager

# Variables
$CommunityManagers = '10.220.3.25'
$CommunityString = 'MySuperSecretSNMPCommunity'
 
# Check if the SNMP Service is already installed, if not then install it
$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 SNMP Servcie is enabled
If ($check.Installed -eq 'True'){
    # Set the configured SNMP Manager(s)
    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 ($CommunityManagers in $CommunityManagers){
        reg add 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers'; /v $i /t REG_SZ /d $CommunityManagers /f | Out-Null
        $i++
        }
    # Set the SNMP Community String(s) as read only
    Foreach ( $string in $CommunityString){
        reg add 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\ValidCommunities'; /v $string /t REG_DWORD /d 4 /f | Out-Null
        }
}

PRTG was and still is a great monitoring tool, however I know a number of users are starting to look else where due to their price increases.


Leave a Reply

More Posts