by L7Tech at 2012-10-20 04:40:46
Hi,by L7Tech at 2012-10-21 05:38:41
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
Found one library:by megamorf at 2012-10-21 11:40:05
http://sharpsnmplib.codeplex.com/
but when I try Add-Type .\sharpsnmplib.cf35.dll I’m getting compiler errors:
"Unexpected character ''"
[quote="L7Tech"]Found one library:by Klaas at 2012-10-22 00:01:35
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.
Just download and install Net-SNMP: http://www.net-snmp.org or on sourceforge.by L7Tech at 2012-10-22 14:17:00
restart Powershell and you can use snmpwalk,snmpget or snmpset.
MIB files can usually be found at the vendors or on install media.
[quote]Add-Type (Resolve-Path .\sharpsnmplib.cf35.dll)[/quote]by L7Tech at 2012-10-22 14:36:58
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]
[quote]Just download and install Net-SNMP: http://www.net-snmp.org or on sourceforge.by Klaas at 2012-10-23 00:08:06
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.
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]<br>$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]