#powershell SNMP Services Administration (Part 2)

Multiple “Community name” and the matching “Trap destinations” can be defined using the Traps tab in the SNMP service. Each community name exists in its own key (node) under:

HKLM:\System\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration

within which one or more trap destinations are stored as properties (REG_SZ) in this registry location.

For example, you need to add a new community name and a host as the trap destination. This can be achieved as follows:

$communityName = "CommunityName01"
$serverName = "FS01"
$registryPath = "HKLM:\System\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration"
#
# create community name if not exists
if (-not (Test-Path "$registryPath\$communityName"))
{
New-Item -Name $communityName -Path $registryPath
}
#
# get current number of trap destinations and increase by 1 to add as new item
$i = (Get-ItemProperty "$registryPath\$communityName" | Measure).count
$i++
#
New-ItemProperty -Name $i -Value $serverName -Path "$registryPath\$communityName"

A manual check is as simple as below:

cd "HKLM:\System\CurrentControlSet\Services\SNMP\Parameters"
dir .\TrapConfiguration

Similarly, removal of the registry key and properties is carried out as such:

cd "HKLM:\System\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration"
#remove community name and associated trap destinations
rm $communityName

 

Bookmark the permalink.

Leave a Reply