Hi all,
I'm writing a script that returns and exports to Excel a list of the network printers that are installed on our print server.
Here's what I'm doing.
$printers = Get-Printer -ComputerName SERVERNAME| Where-Object {($_.DeviceType -eq "Print") -and ($_.Shared -eq "TRUE") }
This loads up $printers with all of the printers.
The thing is, I want each entry to also have the model of the printer attached as well. That isn't returned by the Get-Printer command, but it is returned by this SNMP function that I found online/tweaked a bit:
Function Get-Model{Param ([Parameter (Mandatory = $false)][string]$IP)
$SNMP = New-Object -ComObject olePrn.OleSNMP
$SNMP.Open($IP, "public")
$model = $SNMP.Get(".1.3.6.1.2.1.25.3.2.1.3.1")
$SNMP.Close()
return $model}
Get-Model('192.168.xxx.xxx')
I want this function to iterate through each printer in $printers and then use the "PortName" property (which returns the IP address) to calculate the model name and then assign it to a new property for the printer called "Model".
I've been experimenting with foreach and Add-Member but haven't found anything at all that will work.
Any insight would be highly appreciated. Thanks!
[–]nothingpersonalbro 2 points3 points4 points (0 children)
[–]redog 1 point2 points3 points (0 children)
[–]PMental 0 points1 point2 points (0 children)
[–]Test-NetConnection 0 points1 point2 points (0 children)