PoshCode Archive  Artifact [e17335bf2e]

Artifact e17335bf2ea6bd9512dba8c6b59cd391b40b58ff8c07b2327f1191bb54f35f11:

  • File NetSnmp-psm1.ps1 — part of check-in [99b480dcf0] at 2018-06-10 12:56:42 on branch trunk — Beginnings of a PowerShell v2 module that serves as a convenience wrapper for the Net-SNMP executables. (user: halr9000 size: 1018)

# encoding: ascii
# api: powershell
# title: NetSnmp.psm1
# description: Beginnings of a PowerShell v2 module that serves as a convenience wrapper for the Net-SNMP executables.
# version: 0.1
# type: function
# author: halr9000
# license: CC0
# function: Get-SnmpValue
# x-poshcode-id: 1238
# x-archived: 2016-11-07T08:33:05
# x-published: 2009-07-28T12:37:00
#
#
#requires -version 2
$NetSnmp = Join-Path $env:programfiles "Net-SNMP\bin"
	if ( -not ( Test-Path "$NetSnmp\snmpwalk.exe" ) ) {
		Throw "Net-SNMP binaries not found in $NetSnmp. Please install to this folder `
			or edit the NetSnmp variable as appropriate."
	}

# Modeled after SNMPWALK http://www.net-snmp.org/docs/man/snmpwalk.html
function Get-SnmpValue {
	param (
		[Parameter( Position = 0, Mandatory = $true )] $Agent,
		[Parameter( Position = 1, Mandatory = $true )] $OID,
		$Port = 161,
		$Community = "public",
		$Version = "2c"
	)
	&"$NetSnmp\snmpwalk.exe" "-v$Version" "-c$Community" "${Agent}:$Port" "$OID"
}