Skip to content

Instantly share code, notes, and snippets.

@vincent1890
Forked from Santaro255/printer_snmp_info.ps1
Created May 28, 2024 18:33
Show Gist options
  • Save vincent1890/7e4ec61539ca0b1a24d2a893cde3a5eb to your computer and use it in GitHub Desktop.
Save vincent1890/7e4ec61539ca0b1a24d2a893cde3a5eb to your computer and use it in GitHub Desktop.
if (!(Get-InstalledModule -Name Proxx.SNMP)) {
try {Install-Module -Name Proxx.SNMP}
catch {Write-Host "`nYou need `"Proxx.SNMP`" module. Restart with administrator rights for installation or do it manually. (Install-Module -Name Proxx.SNMP)" -BackgroundColor DarkRed; break}}
$target=Read-Host -Prompt "Enter printer ip or hostname"
$connect=Test-Connection -ComputerName $target -Count 1 -ErrorAction SilentlyContinue
$ip=$connect.IPV4Address.IPAddressToString
$items=@{Model="1.3.6.1.2.1.25.3.2.1.3.1";#"1.3.6.1.2.1.43.5.1.1.16.1";
SN="1.3.6.1.2.1.43.5.1.1.17.1"
Name="1.3.6.1.2.1.1.5.0";
Uptime="1.3.6.1.2.1.1.3.0";
Printed="1.3.6.1.2.1.43.10.2.1.5.1.1"
TotalPrinted="1.3.6.1.2.1.43.10.2.1.4.1.1"
TonerLeft="1.3.6.1.2.1.43.11.1.1.9.1.1"
TonerMax="1.3.6.1.2.1.43.11.1.1.8.1.1"
}
function gvalue($name) {
$value=Invoke-SnmpGet -IpAddress $ip -Oid $items.$name -ErrorAction SilentlyContinue
return $value.Value
}
if (!($connect)) {Write-Host "`nHost unreachable" -BackgroundColor DarkRed}
else {
Write-Host "`nName Value"
Write-Host "----- -----"
Write-Host "Model: "$(gvalue("Model"))
Write-Host "Serial Number: "$(gvalue("SN"))
Write-Host "Printer name: "$(gvalue("Name"))
Write-Host "Uptime: "$(gvalue("Uptime"))
Write-Host "Printed since last start: "$(gvalue("Printed"))
Write-Host "Total printed: "$(gvalue("TotalPrinted"))
Write-Host "Toner left: "$(gvalue("TonerLeft"))
Write-Host "Toner max: "$(gvalue("TonerMax"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment