Skip to content

Instantly share code, notes, and snippets.

@kfparri
Created April 9, 2021 16:18
Show Gist options
  • Save kfparri/637317f47029f048c49e2489edfb1ba0 to your computer and use it in GitHub Desktop.
Save kfparri/637317f47029f048c49e2489edfb1ba0 to your computer and use it in GitHub Desktop.
Query list of Cisco devices via SNMP
192.168.1.254
192.168.1.253
# Get a list of all the IPs to check
# Make sure the ips.txt file is in the same directory as this script and each IP is on it's own line
$ips = Get-Content -Path 'ips.txt'
# Set the community string
$commStr = 'public'
foreach($ip in $ips){
# Create a new SNMP object
$snmp = New-Object -ComObject olePrn.OleSNMP
# Connect to the IP address with the community string,
$snmp.open($ip, $commStr, 2, 1000)
# Request the device description (you can change this to a different tag if you need to or add another)
$result = $snmp.get('.1.3.6.1.2.1.1.1.0')
# write the result to the console
Write-Output "Processing $ip"
Write-Output $result
Write-Output "---------------------------"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment