Talk:SNMP and PowerShell

From vWiki
Jump to: navigation, search

Question:

Hi there,

really useful info on getting PS to talk to SNMP, thanks.

One thing I can't figure out in your examples though:

PS C:\Users\simon\Documents\Scripts> . .\lib\SNMP-Funcs.ps1 What does this line do? I can't find any reference to a script called SNMP-Funcs.ps1 elsewhere in the article.

I've followed your steps and everything *seems* to be working except I get no output when running the "get" and "walk" scripts and I suspect the above line my be the culprit!

Thanks in advance,

I.



Response:

OK, I realize no one has responded in a year, but perhaps someone will find this info useful...

The author is just using a different file name called '. .\lib\SNMP-Funcs.ps1' in his example. It is the same as 'SNMP.ps1'

In the example below, BigDipper is my 'scripts' folder. I have a sub-folder under it called 'lib' with SNMP.ps1 in it and a sub-folder under 'lib' called 'LexTmSharpSNMP' with 'SharpSnmpLib.dll' in it:

.\lib\snmp.ps1

.\lib\LexTmSharpSNMP\SharpSnmpLib.dll

Example:

PS C:\users\tyson\Downloads\snmp\PowerShell\BigDipper> . .\lib\SNMP.ps1

PS C:\users\tyson\Downloads\snmp\PowerShell\BigDipper> Load-SnmpAssembly | fl

CodeBase  : file:///C:/users/tyson/Downloads/snmp/PowerShell/BigDipper/lib/LexTmSharpSNMP/SharpSnmpLib.dll EntryPoint  : EscapedCodeBase  : file:///C:/users/tyson/Downloads/snmp/PowerShell/BigDipper/lib/LexTmSharpSNMP/SharpSnmpLib.dll FullName  : SharpSnmpLib, Version=7.5.10510.1, Culture=neutral, PublicKeyToken=db32884da8b9d0dd GlobalAssemblyCache  : False HostContext  : 0 ImageFileMachine  : ImageRuntimeVersion  : v2.0.50727 Location  : C:\users\tyson\Downloads\snmp\PowerShell\BigDipper\lib\LexTmSharpSNMP\SharpSnmpLib.dll ManifestModule  : SharpSnmpLib.dll MetadataToken  : PortableExecutableKind : ReflectionOnly  : False


PS C:\users\tyson\Downloads\snmp\PowerShell\BigDipper> Invoke-SNMPget "192.168.1.154" ".1.3.6.1.4.1.318.1.1.4.4.2.1.3.1"

OID Data

--- ----

.1.3.6.1.4.1.318.1.1.4.4.2.1.3.1 1


PS C:\users\tyson\Downloads\snmp\PowerShell\BigDipper>

The Wiki is pulling all my spaces out of the output between the final OID and the Data fields. It's returning:

OID = .1.3.6.1.4.1.318.1.1.4.4.2.1.3.1

Data = 1

I hope these examples help others out.

-Tyson Flint

Request for Invoke-SnmpSet

These scripts have been great in that I can now capture SNMP info into PowerShell objects. It would be even a nicer tool if we could have an additional routine created for setting SNMP values. I'm not strong in C#, but believe this reference could come in handy in writing the script:

http://help.sharpsnmp.com/html/M_Lextm_SharpSnmpLib_Messaging_Messenger_Set.htm

Thanks again for putting together these tools!

-Tyson Flint