I needed to come up with a way to create some logs of the usage on the fleet of 10 Konica printers across four locations / print servers.
These logs will be used to validate the pricing figures our printer support vendor provides (pricing is based on estimated / averaged usage per device - that data is audited on a quarterly basis, via automated auditing tools on each print server - FM Audit).
Currently - Without any of our own historical data - We have to take the vendors word, that those quarterly averages are 'OK'...
So, someone from accounting asked me for help.
The below script collects settings info for all of the Konica printers on each of the print servers, then uses the 'PortName' (IP address) to run an SNMP query on each device (SNMP must be enabled in the devices network settings).
The critical items are the OID's.
Figuring out which ones pull in the values for 'black' and for 'color' were the first challenge.
Once I got that figured out - It took me a while to find the OID that gathers the devices serial number - I could NOT find this documented anywhere, and AI (Copilot, Gemini, Claude) wasn't able to either.
For this last bit - I ended up walking (snmpwalk) through ALL 7125 OID's to locate the one that gathers the serial number.
wsl snmpwalk -v2c -c public <printer IP> 1.3.6.1 > 'C:\Users\richie\Documents\PoSh_Stuff\OID_walk.txt'
And looking for the serial number I already knew for that printer.
Select-String -Path 'C:\Users\richie\Documents\PoSh_Stuff\OID_walk.txt' -Pattern '<SerialNumber>'
OID_walk.txt:460:iso.3.6.1.2.1.43.5.1.1.17.1 = STRING: "<SerialNumber>"
Posting what I figured out.
I will pipe '$Report' to a Csv, and save it accordingly.
I'll be scheduling this to run on a quarterly basis - And handing the Csv's over to accounting when they ask for them.
$AllKonica = @() ("Site1,site2,site3,site4").Split(',') | % { If (Test-Connection $_ -Count 1 -ErrorAction SilentlyContinue) { $AllKonica += Get-Printer -ComputerName $_ | ? { $_.DriverName -match 'Konica' -and $_.PortName -NOTmatch "portprompt|microsoft|_"} | Select ComputerName, Name, PortName, DriverName, Comment } } $Report = @() $AllKonica | % { $PrintServer = $_.ComputerName $PrinterIP = $_.PortName $PrinterName = $_.Name $Sn = $_.Comment $SNMP_Community = "public" If (Test-Connection $PrinterIP -Count 1 -ErrorAction SilentlyContinue) { $OIDs = [Ordered]@{ "Model" = ".1.3.6.1.4.1.18334.1.1.1.3.5.2.2.0" "SerialNo" = ".1.3.6.1.2.1.43.5.1.1.17.1" "Total" = ".1.3.6.1.4.1.18334.1.1.1.5.7.2.1.1.0" "Print_Black" = ".1.3.6.1.4.1.18334.1.1.1.5.7.2.2.1.5.1.2" "Copy_Black" = ".1.3.6.1.4.1.18334.1.1.1.5.7.2.2.1.5.1.1" "Print_Color" = ".1.3.6.1.4.1.18334.1.1.1.5.7.2.2.1.5.2.2" "Copy_Color" = ".1.3.6.1.4.1.18334.1.1.1.5.7.2.2.1.5.2.1" "Print_2Color" = ".1.3.6.1.4.1.18334.1.1.1.5.7.2.2.1.5.4.2" "Copy_2Color" = ".1.3.6.1.4.1.18334.1.1.1.5.7.2.2.1.5.4.1" } $snmp = New-Object -ComObject OlePrn.OleSNMP try { $snmp.Open($PrinterIP, $SNMP_Community, 2, 1200) $Data = [Ordered]@{ "Printer" = "$PrinterName - $PrinterIP" } foreach ( $Key in $OIDs.Keys ) { try { $Value = $snmp.Get($OIDs[$Key]) if ( $null -eq $Value -or $Value -eq "" ) { $Data[$Key] = 0 } #{ $Data[$Key] = $null } else { $Data[$Key] = $Value } } # END 'try' # 2 # catch { $Data[$Key] = $null } catch { $Data[$Key] = 0 } } # END 'foreach ($Key in $OIDs.Keys)' $TotalColor = [int]$Data["Print_Color"] + [int]$Data["Print_2Color"] + [int]$Data["Copy_Color"] + [int]$Data["Copy_2Color"] $TotalBlack = [int]$Data["Print_Black"] + [int]$Data["Copy_Black"] $Report += [PSCustomObject][Ordered]@{ "Model" = $Data["Model"] "SerialNo" = $Data["SerialNo"] "Printer" = $Data["Printer"] "Total" = $Data["Total"] "Black" = $TotalBlack "Color" = $TotalColor } } # END 'try' # 1 catch { Write-Host "Connection failed: $PrintServer -> $PrinterIP ($PrinterName)" -F 14 } finally { $snmp.Close() } } # END 'If (Test-Connection...' else { $Report += [PSCustomObject][Ordered]@{ "Model" = "Unk" "SerialNo" = $Sn "Printer" = "$PrinterName - Unreacheable" "Total" = "NULL" "Black" = "NULL" "Color" = "NULL" } } # END 'else' } # END '$AllKonica | %' $Report | ft
No comments:
Post a Comment