The greatest challenge to any thinker is stating the problem in a way that will allow a solution

Bertrand Russell


On 12 Feb 2013


Tags: , ,

This post provides an example of how to gather some basic system info from an SNMP enabled host using PowerShell.

Why wouldn’t I use WMI?

You could in many circumstances.  In general the amount of information you can get from WMI is far greater than what’s available via SNMP, however,

  • In order to access WMI you often end up requiring full admin rights on the target systems, which is a security nightmare.
  • WMI is Windows platform dependant, whereas SNMP is normally available for any enterprise device.

PowerShell and SNMP

In order to be able to use PowerShell as an SNMP client you need to use a free 3rd party .NET library.  It wasn’t specifically created with PowerShell in mind, but as its .NET, this isn’t a problem.  There are of course paid for PowerShell SNMP snap-ins (but why would you pay for something you can legally get for free?).

For further info on how to get yourself set-up, see my Wiki page –

In order to run the script below you need to have the SharpSnmpLib.dll file, so that PowerShell can run SNMP operations.  Plus the script functions from the Wiki page in a file called SNMP.ps1, these act as a wrapper for the DLL.  See for futher info.

 The Script

$SNMPhost = ""     # IP address of host to query
. .\lib\SNMP.ps1                 # Include SNMP helper functions (see above)
# Load SNMP assembly (update path to DLL as required)
[reflection.assembly]::LoadFrom( (Resolve-Path ".\lib\LexTmSharpSNMP\SharpSnmpLib.dll") )
# Basic queries
Write-Host ("Hostname   : " + (Invoke-SnmpGet $SNMPhost .
Write-Host ("Description: " + (Invoke-SnmpGet $SNMPhost .
Write-Host ("System     : " + (Invoke-SnmpGet $SNMPhost .
Write-Host ("Memory (MB): " + [math]::Round(((Invoke-SnmpGet $SNMPhost ., 0) )
# Walk whole of MIB2 Device Table
$devices = Invoke-SnmpWalk $SNMPhost .
#Extract number of processors and disks
Write-Host ("Processors : " + ($devices |?{$_.Data -eq "."} | Select -ExpandProperty Data).count)
Write-Host ("Disks      : " + ($devices |?{$_.Data -eq "."} | Select -ExpandProperty Data).count)
# Get index ID's of disks, and get some data for each
$diskIDs = $devices |?{$_.Data -eq "."} | Select -ExpandProperty OID | % {$_ -Replace ".", ""}
$disklist = ""
foreach ($diskID in $diskIDs) {
$disklist += (Invoke-SnmpGet $SNMPhost .$diskID).Data + "  "
Write-Host ("Disks      : " + $disklist)

Example Output

From a Windows system expect something like…

Hostname   : TEST-SVR
Description: Hardware: x86 Family 16 Model 2 Stepping 3 AT/AT COMPATIBLE - Software: Windows Version 5.2 (Build 3790 Multiprocessor Free)
System     : .
Memory (MB): 1023
Processors : 1
Disks      : 3
Disks      : A:\ C:\ D:\

and from a Linux system something like…

Hostname   : sys1
Description: Linux 2.7.3
System     : .
Memory (MB): 250
Processors : 1
Disks      : 3
Disks      : SCSI disk (/dev/sda)  SCSI disk (/dev/sdb)  SCSI disk (/dev/sdc)


Leave a Reply

XHTML: You can use these tags if you know what they are: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

ERROR: si-captcha.php plugin says GD image support not detected in PHP!

Contact your web host and ask them why GD image support is not enabled for PHP.

ERROR: si-captcha.php plugin says imagepng function not detected in PHP!

Contact your web host and ask them why imagepng function is not enabled for PHP.