Powershell script for snmpwalk - to scan multiple devices

  1. Ready list of IPs in C:\temp\NetworkCIs.txt
  2. Run the below script after updated the snmp community below
  3. Get the result from C:\temp\snmp.csv

Function snmp
{
param([string]$CIs)
foreach ($CI in $CIs)
{
$table=[ordered]@{ Device = $CI; Result = “”}
$command = “C:\usr\bin\snmpwalk.exe -v 2c -c snmp community -t 2 " + $CI + " .1.3.6.1.2.1.1.5.0”
#Write-host $command
$result = Invoke-expression $command
$result = $result -replace “SNMPv2-MIB::sysName.0 = STRING: “,””
Write-host "2OK:- " + $result
if ($result)
{
$table.Result = $result
new-object -type PSObject -prop $table
} else
{
$table.Result = “No response”
new-object -type PSObject -prop $table
}
}
}
$NetworkCIs = Get-Content ‘C:\Temp\NetworkCIs.txt’
snmp $NetworkCIs | export-csv ‘C:\temp\snmp.csv’ -notypeinformation