r/PowerShell • u/zaphodikus • Apr 28 '26
snmp commandlet documentation
I'm a bit confused by the gaps in snmp documentation, for all languages and the entire stack itself, so I figured, hey Powershell will be easier than C++. But it seems it's just not. I read amongst others this posthttps://vwiki.co.uk/SNMP_and_PowerShell , and it's still clear as mud, how do docs for the "open" function
$SNMP.open($IPAddresses[1], "public", 2, 3000)
What on earth is 2 ?
3000 is as far I can figure a timeout, but where are the Powershell docs?
I call Get, and I just get an error
> $SNMP.Get(".1.3.6.1.2.1.2.1")
Unknown Error
At line:1 char:1
+ $SNMP.Get(".1.3.6.1.2.1.2.1")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
I'm querying my local interface I assume, and it's all guesswork as to what that error means because I was expecting an interface ID back, a simple number?
4
u/ka-splam Apr 28 '26
https://old.reddit.com/r/PowerShell/comments/zqlc5r/snmp_query/
The link says "all of the scripts below utilises the #SNMP (SharpSNMP) Suite for .NET/Mono". That isn't a cmdlet, or part of PowerShell, it's a third party C# library; it's like saying "I opened a .mp4 file with [system.io.file]::open() but where are the PowerShell documents for working with MP4 video?". There aren't any.
SNMP is not connected to PowerShell, you either need to find a thing which can do it and read that documentation, or build it yourself; note that the SNMP stands for Simple but it's not a simple protocol.
3
u/justaguyonthebus Apr 28 '26
Search for Powershell snmp module and start from there. I see there are several and that should make things much easier.
It looks like you are reaching up into dotnet so check the C# docs if you continue down that path. Powershell is fairly well documented as long as you are doing native powershell. But Powershell is flexible and will let you interact with things that aren't so well documented.
2
u/_MisterSir Apr 28 '26
I’d recommend using snmpwalk.exe. That’s how I did it anyways. Used Crescendo to create a few cmdlets that wrapped around the executable and went to town. I’m not at a computer but I’ll try to remember to share my code when I’m able
1
u/zaphodikus Apr 28 '26
Is it possible to use the Powershell/COM interface to walk the tree and read the names of all the objects or leaves in a node? I saw a powershell walk script yesterday, but it uses a lib from a 3rd party app. I'm struggling to understand the getnext command I suspect.
1
u/jpochedl Apr 28 '26
To tell you what 2 is, we need to know what type of object is $SNMP... That 2 is going to be a parameter and the definition is part of the object's info.... Based on the error, looks like some sort of COM object or .Net object.... Show us more of the script....
1
u/purplemonkeymad Apr 28 '26
Dotnet and MS COM methods are typically documented somewhere so you can see the methods/properties. In this case a quick search for the class name gives you this: https://learn.microsoft.com/en-us/windows-hardware/drivers/print/isnmp-automation-interface
That contains the methods including what each argument of open is.
You will notice this is not Powershell and that is as it was probably written before it existed. You are however working with the same classes.
1
u/thehuntzman Apr 28 '26 edited Apr 28 '26
EDIT: The error you are getting using the legacy COM object is because olePrn.OleSNMP ONLY supports SNMP v1. You have to use a 3rd party library if you want 2c or 3 (see below)
I actually have several scripts that query SNMP on various devices using https://github.com/lextudio/sharpsnmplib
Get the DLL from Nuget, then import it (add-type/import-module/using/etc... your choice)
Here are some examples:
...or for a single OID:
1
u/itasteawesome Apr 29 '26
I see you solved your original issue, but why are you writing any custom code to do snmp at all in 2026? Especially in powershell?
Gosnmp is far and away the most popular library for this, save yourself some hassle and start there? https://github.com/gosnmp/gosnmp
1
u/coaster_coder Apr 28 '26
https://github.com/steviecoaster/Summit24/blob/main/Crescendo/snmp.crescendo.ps1