How to get SNMP info from Powershell

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 3 months ago.

  • Author
    Posts
  • #6438

    by L7Tech at 2012-10-20 04:40:46

    Hi,
    as far as I can tell, PowerShell does not have any built in ways to work with SNMP.
    I’m looking to retrieve SNMP info from different devices (Dell servers, firewalls, switches) using PowerShell.
    I think a .net library could get me some nice objects to work with, but I’ve only found expensive commercial ones.
    Would anyone have a recent example of retrieving SNMP info using PowerShell and free libraries?
    Maybe Powershell v3 would make it easier. Or the SNMP WMI Provider if it’s still around (I've seen a note somewhere on Technet that its not in Server 2012 anymore).
    Maybe there is some other way to get to the info described in the MIBs?
    Example MIBs and their description:
    ftp://ftp.us.dell.com/sysman/DCPEMIBs.exe
    ftp://ftp.us.dell.com/sysman/DCPEMIBs.txt

    by L7Tech at 2012-10-21 05:38:41

    Found one library:
    http://sharpsnmplib.codeplex.com/
    but when I try Add-Type .\sharpsnmplib.cf35.dll I'm getting compiler errors:
    "Unexpected character '\'"
    🙁

    by megamorf at 2012-10-21 11:40:05

    [quote="L7Tech"]Found one library:
    http://sharpsnmplib.codeplex.com/
    but when I try Add-Type .\sharpsnmplib.cf35.dll I'm getting compiler errors:
    "Unexpected character '\'"
    ]

    Have you tried using the full path instead of the relative path? Like so:

    Add-Type (Resolve-Path .\sharpsnmplib.cf35.dll)

    Can't test that right now. You might have to use the Dot-notation to select the path property in case add-type doesn't use the path property automatically.

    by Klaas at 2012-10-22 00:01:35

    Just download and install Net-SNMP: http://www.net-snmp.org or on sourceforge.
    restart Powershell and you can use snmpwalk,snmpget or snmpset.

    MIB files can usually be found at the vendors or on install media.

    by L7Tech at 2012-10-22 14:17:00

    [quote]Add-Type (Resolve-Path .\sharpsnmplib.cf35.dll)[/quote]
    Here is the full error message:
    [code2=powershell]Add-Type (Resolve-Path .\sharpsnmplib.cf35.dll)
    Add-Type : t:\temp\user\c_z8cxe0.0.cs(1) : Unexpected character '\'
    t:\temp\user\c_z8cxe0.0.cs(1) : >>> C:\scripts\sharpSNMP\sharpsnmplib.cf35.dll
    At line:1 char:9
    + Add-Type < <<< (Resolve-Path .\sharpsnmplib.cf35.dll)
    + CategoryInfo : InvalidData: (t:\temp\user\c_...d character '\':CompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand

    Add-Type : t:\temp\user\c_z8cxe0.0.cs(1) : Unexpected character '\'
    t:\temp\user\c_z8cxe0.0.cs(1) : >>> C:\scripts\sharpSNMP\sharpsnmplib.cf35.dll
    At line:1 char:9
    + Add-Type < <<< (Resolve-Path .\sharpsnmplib.cf35.dll)
    + CategoryInfo : InvalidData: (t:\temp\user\c_...d character '\':CompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand

    Add-Type : t:\temp\user\c_z8cxe0.0.cs(1) : Unexpected character '\'
    t:\temp\user\c_z8cxe0.0.cs(1) : >>> C:\scripts\sharpSNMP\sharpsnmplib.cf35.dll
    At line:1 char:9
    + Add-Type < <<< (Resolve-Path .\sharpsnmplib.cf35.dll)
    + CategoryInfo : InvalidData: (t:\temp\user\c_...d character '\':CompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand

    Add-Type : t:\temp\user\c_z8cxe0.0.cs(1) : A namespace does not directly contain members such as fields or methods
    t:\temp\user\c_z8cxe0.0.cs(1) : >>> C:\scripts\sharpSNMP\sharpsnmplib.cf35.dll
    At line:1 char:9
    + Add-Type < <<< (Resolve-Path .\sharpsnmplib.cf35.dll)
    + CategoryInfo : InvalidData: (t:\temp\user\c_...elds or methods:CompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand

    Add-Type : Cannot add type. There were compilation errors.
    At line:1 char:9
    + Add-Type < <<< (Resolve-Path .\sharpsnmplib.cf35.dll)
    + CategoryInfo : InvalidData: (:) [Add-Type], InvalidOperationException
    + FullyQualifiedErrorId : COMPILER_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand[/code2]

    by L7Tech at 2012-10-22 14:36:58

    [quote]Just download and install Net-SNMP: http://www.net-snmp.org or on sourceforge.
    restart Powershell and you can use snmpwalk,snmpget or snmpset.[/quote]
    yes, but is there a way to get back objects or its text only?
    I'm looking to retrieve all the info in a MIB to an object and then pick and choose properties from it.
    I guess I could pick and choose first and then get the text for the specific properties as text and create a custom object.
    Having to install software makes this a bit harder too. A self contained SNMP nodule would be nicer.
    I'll try this anyway.

    by Klaas at 2012-10-23 00:08:06

    I've been using this for 4 years to maintain a monitoring and inventory system for switches, printers, routers,modems, computers and even some warehouse machines.
    Sometimes there's quite some string manipulation or extensive logic involved, but you only have to write that once,not?
    this are some examples I use to query cisco switches:
    $serialnr = $(snmpget -v 1 -r 1 -t 2 -c public -O v $adres 1.3.6.1.2.1.47.1.1.1.1.11.1001).split("`"")[-2]
    $type = $(snmpget -v 1 -r 1 -t 3 -c public -O v $adres 1.3.6.1.2.1.47.1.1.1.1.13.1001).split("`"")[-2]
    $GATEWAY = $(snmpget -v 1 -r 1 -t 2 -c public -O v $adres mib-2.16.19.12.0).split(" ")[-1]

You must be logged in to reply to this topic.