Skip to content
Menu
Tech Automation Blog
  • About Author
  • Contact
Tech Automation Blog

List Printers on a Windows Print Server

Posted on February 4, 2020February 27, 2022

This post is about a small script to connect a Windows Print Server remotely and list all Printers attached to the Server.It will also provide printer IP Address, printer status etc.

I will use Microsoft Windows Operating System WMI provider in Powershell to connect and generate details from the print server. Through this script, I will collect Printer Name, IP address, Type , status for each printer on the server with exception of “XPS” printers. You may add PDF, One Note etc. in exclusion list based on your requirements.

Make sure you have connectivity to the remote server and authorization to run script remotely. I will use print server name and the output file path as input to the script.Feel free to update script to set those as parameters.

Here is the complete script!

$printServerName = "<myprintserver.fqdn>"
$oFile = "<Some Path>\Printers_Detail.csv"
if(Test-Path $oFile){
    Remove-Item -Path $oFile -Force
}
"Server Name,Printer Name,Type,IP Address,Staus" | Out-File $oFile -append -Encoding ASCII	

$printers = Get-WmiObject -class win32_printer -ComputerName $printServerName
ForEach($printer in $printers)
{
   $IPAddress = $printerName = $printerType = $printerStatus =  ""
   if($null -ne $printer -Or $printer.Name -notlike "*XPS*") # I am excluding XPS Printers. Feel free to add your exclusions here
   {
		if($null -ne $printer.Attributes){
			if($printer.Attributes -eq 64){ # Based on my experience, Attribute 64 is for Local printers. You may have different value. Verify at your end and update accordingly.
                $printerType = "Local Printer"
            }
            else{
                $printerType = "Network/Session Printer"
            }
			$printerName = $printer.Name
			$ports = Get-WmiObject Win32_TcpIpPrinterPort -Filter "name = '$($printer.Portname)'" -ComputerName $printServerName
			ForEach ($port in $ports){
                if($port.Name -eq $printer.Portname){
                    $IPAddress = $port.HostAddress
                }				
			}
			if (test-Connection -ComputerName $IPAddress -Count 2 -Quiet){
                $printerStatus = "ONLINE"
            } 
            else {
                $printerStatus = "OFFLINE"
            }				
		}	
		"$printServerName,$PrinterName,$printerType,$IPAddress,$printerStatus" | Out-File $oFile -append -Encoding ASCII
	}		
}

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on LinkedIn (Opens in new window) LinkedIn
June 2025
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« May    

Recent Posts

  • Monitor and alert Azure Service Health issues May 5, 2020
  • AWS IAM User access review May 3, 2020
  • Integrate Azure Security Center with Event Hub April 28, 2020
  • Add Tags to Azure Subscription April 24, 2020
  • Automate Azure billing report in Excel March 6, 2020

Categories

©2025 Tech Automation Blog | Powered by SuperbThemes