microsoft:windows:printing:powershell:snippets
Table of Contents
Microsoft - Windows - Printing - PowerShell - Snippets
Get a list of printers with IP and driver
Tested on Windows Server 2016.
Get-Printer | ` Select-Object ` Name, @{Label="IP";Expression={(Get-PrinterPort -Name $_.PortName).PrinterHostAddress}}, DriverName | ` Sort-Object Name
Example output:
Name IP DriverName ---- -- ---------- Brother MFC-7460DN 10.8.2.201 Brother Laser Type1 Class Driver HP LaserJet 4050N 10.8.2.250 HP Universal Printing PCL 6 (v6.3.0) Microsoft Print to PDF Microsoft Print To PDF Microsoft XPS Document Writer Microsoft XPS Document Writer v4 Ricoh_MPC2004 10.8.2.190 RICOH PCL6 UniversalDriver V4.12 Xerox C7025 10.8.2.20 Xerox GPD PCL6 V3.9.520.6.0
Get information about printer ports
Tested on Windows Server 2016.
$arrPrinterPortProperties = "Name","PrinterHostAddress","PrinterHostIp","Protocol","PortNumber","SNMPCommunity","SNMPEnabled","SNMPIndex" $objPrinterPorts = Get-Printerport $objResult = @() foreach ($objPrinterPort in $objPrinterPorts) { $objPrinterCimInstanceProperties = (Get-PrinterPort -Name $objPrinterPort.Name).CimInstanceProperties $objTemp = {} | Select-Object $arrPrinterPortProperties $objDesiredPrinterProperties = $objPrinterCimInstanceProperties | Where-Object {$arrPrinterPortProperties -contains $_.Name} | Select-Object Name,Value $objTemp.Name = $objPrinterPort.Name $objTemp.PrinterHostAddress = ($objDesiredPrinterProperties | Where-Object {$_.Name -match "PrinterHostAddress"}).Value $objTemp.PrinterHostIp = ($objDesiredPrinterProperties | Where-Object {$_.Name -eq "PrinterHostIp"}).Value $objTemp.Protocol = ($objDesiredPrinterProperties | Where-Object {$_.Name -eq "Protocol"}).Value $objTemp.PortNumber = ($objDesiredPrinterProperties | Where-Object {$_.Name -eq "PortNumber"}).Value $objTemp.SNMPCommunity = ($objDesiredPrinterProperties | Where-Object {$_.Name -eq "SNMPCommunity"}).Value $objTemp.SNMPEnabled = ($objDesiredPrinterProperties | Where-Object {$_.Name -eq "SNMPEnabled"}).Value $objTemp.SNMPIndex = ($objDesiredPrinterProperties | Where-Object {$_.Name -eq "SNMPIndex"}).Value if ( -Not ($objTemp.PrinterHostAddress -eq $null)) { $objResult += $objTemp } } $objResult | Format-Table -AutoSize
Example output:
Name PrinterHostAddress PrinterHostIp Protocol PortNumber SNMPCommunity SNMPEnabled SNMPIndex ---- ------------------ ------------- -------- ---------- ------------- ----------- --------- 10.8.2.190 10.8.2.190 1 9100 public True 1 10.8.2.190_1 10.8.2.190 1 9100 public True 1 10.8.2.20 10.8.2.20 2 515 public True 1 10.8.2.201 10.8.2.201 2 515 public True 1 10.8.2.20_1 10.8.2.20 2 515 public True 1 10.8.2.250 10.8.2.250 1 9100 public False 1 10.8.2.250_1 10.8.2.250 1 9100 public False 1
microsoft/windows/printing/powershell/snippets.txt · Last modified: 2023/03/16 13:50 by bas