Here is My script (using http://vwiki.co.uk/SNMP_and_PowerShell#PowerShell_v1_and_v2 informations) :
param(
[string]$pIP
)
[reflection.assembly]::LoadFrom( (Resolve-Path "C:\MA_Scripts\lib\SharpSnmpLib.dll") )
function New-GenericObject {
# Creates an object of a generic type - see http://www.leeholmes.com/blog/2006/08/18/creating-generic-types-in-powershell/
param(
[string] $typeName = $(throw “Please specify a generic type name”),
[string[]] $typeParameters = $(throw “Please specify the type parameters”),
[object[]] $constructorParameters
)
## Create the generic type name
$genericTypeName = $typeName + ‘`’ + $typeParameters.Count
$genericType = [Type] $genericTypeName
if(-not $genericType)
{
throw “Could not find generic type $genericTypeName”
}
## Bind the type arguments to it
[type[]] $typedParameters = $typeParameters
$closedType = $genericType.MakeGenericType($typedParameters)
if(-not $closedType)
{
throw “Could not make closed type $genericType”
}
## Create the closed version of the generic type
,[Activator]::CreateInstance($closedType, $constructorParameters)
}
function Invoke-SnmpWalk ([string]$sIP, $sOIDstart, [string]$Community = "public", [int]$UDPport = 161, [int]$TimeOut=3000) {
# $sOIDstart
# $TimeOut is in msec, 0 or -1 for infinite
# Create OID object
$oid = New-Object Lextm.SharpSnmpLib.ObjectIdentifier ($sOIDstart)
# Create list for results
$results = New-GenericObject System.Collections.Generic.List Lextm.SharpSnmpLib.Variable # PowerShell v1 and v2
# $results = New-Object 'System.Collections.Generic.List[Lextm.SharpSnmpLib.Variable]' # PowerShell v3
# Create endpoint for SNMP server
$ip = [System.Net.IPAddress]::Parse($sIP)
$svr = New-Object System.Net.IpEndPoint ($ip, 161)
# Use SNMP v2 and walk mode WithinSubTree (as opposed to Default)
$ver = [Lextm.SharpSnmpLib.VersionCode]::V2
$walkMode = [Lextm.SharpSnmpLib.Messaging.WalkMode]::WithinSubtree
# Perform SNMP Get
try {
[Lextm.SharpSnmpLib.Messaging.Messenger]::Walk($ver, $svr, $Community, $oid, $results, $TimeOut, $walkMode)
} catch {
Write-Host "SNMP Walk error: $_"
Return $null
}
$ClientsSSID = @{}
foreach ($var in $results) {
if( $var.Id.ToString().StartsWith(".1.3.6.1.4.1.26928.1.1.1.2.1.2.1.10.") ) {
$SSID = $var.Data.ToString()
if($ClientsSSID.ContainsKey($SSID)){
$ClientsSSID.Set_Item($SSID,$ClientsSSID.Get_Item($SSID)+1)
}else{
$ClientsSSID.add($SSID,1)
}
}
}
write-host '<?xml version="1.0" encoding="Windows-1252" ?>'
write-host '<prtg>'
ForEach($client in $ClientsSSID.keys){
write-host " <result>"
write-host " <channel>$client</channel>"
write-host " <value>",$ClientsSSID.Get_Item($client),"</value>"
write-host " </result>"
}
write-host "</prtg>"
}
Invoke-SnmpWalk $pIP "1.3.6.1.4.1.26928.1.1.1.2.1.2" "xxxx"
this works well
Add comment