Public/Invoke-SNMPGet.ps1
function Invoke-SNMPGet { <# .SYNOPSIS Perform a SNMP Get Request and return the results .DESCRIPTION This can be used to perform a simple Get request against one or more hosts. Only SNMP v1 and v2 is supported at this time. SNMP v3 is not supported. .NOTES Uses the SnmpSharpNet library (http://www.snmpsharpnet.com/) Inspired by http://vwiki.co.uk/SNMP_and_PowerShell #> [CmdletBinding()] param ( #The OID you wish to lookup in numerical format (sorry, no MIB resolution supported). Defaults to System.SysUptime.0 (1.3.6.1.2.1.1.3.0) [String]$OID = "1.3.6.1.2.1.1.3.0", #The DNS Name or IP Address to test. Defaults to localhost if not specified [ValidateScript({[System.Net.Dns]::GetHostAddresses("$PSItem")})] [String]$ComputerName = "localhost", #SNMP Community String to test with. Defaults to "public" if not specified [String]$Community = "public", #SNMP Version to use. Defaults to Version 2 [ValidateSet("Ver1","Ver2")] [String]$Version = "Ver2" ) $SNMP = new-object SnmpSharpNet.SimpleSnmp($ComputerName,$Community) #We want errors to be thrown for troubleshooting $SNMP.SuppressExceptions = $false #Check that the SNMP engine was initialized correctly if (!$SNMP.Valid) {throw "SNMP engine was not initialized correctly. Please check that your hostname or IP is correct and you have specified a community string"} $ErrorActionPreference = "Stop" $SNMPGetResult = $SNMP.Get([SnmpSharpNet.SnmpVersion]::$Version,$OID) $ErrorActionPreference = "Continue" $SNMPGetResultProps = [ordered]@{} $SNMPGetResultProps.ComputerName = $ComputerName $SNMPGetResultProps.OID = $OID $SNMPGetResultProps.Type = } #Invoke-SNMPGet |