# encoding: ascii
# api: powershell
# title: Send SNMP trap
# description: This will send an SNMP trap to the specified manager (hostname). The script isn’t very flexible, but it’s a good example of how to build traps using SharpSNMPLib. External requirementss:
# version: 1.3.6
# author: halr9000
# license: CC0
# x-poshcode-id: 4835
# x-archived: 2015-07-20T04:32:25
# x-published: 2015-01-23T18:29:00
#
# Two DLLs (see below) from SharpSNMPLib project: http://sharpsnmplib.codeplex.com/
# New-GenericObject.ps1 script from http://www.leeholmes.com/blog/CreatingGenericTypesInPowerShell.aspx (also in poshcode)
#
Param ( $DestinationHost )
Add-Type -Path "C:\Program Files\LeXtudio Software\sharpsnmplib.dll"
Add-Type -Path "C:\Program Files\LeXtudio Software\SharpSnmpLib.Controls.dll"
$manager = [system.Net.Dns]::Resolve( $DestinationHost ).AddressList[0]
$TrapDest = New-Object Net.IPEndPoint( $manager, 162 )
[Lextm.SharpSnmpLib.Messaging.Messenger]::SendTrapV1( $TrapDest,
[IPAddress]::Loopback,
[Lextm.SharpSnmpLib.OctetString]"public",
[Lextm.SharpSnmpLib.ObjectIdentifier]"1.3.6",
[Lextm.SharpSnmpLib.GenericCode]::ColdStart,
0,
0,
( New-GenericObject.ps1 system.collections.generic.list lextm.sharpsnmplib.variable )
)