Getting information from all installed printers on a print server can be an impossible task without third-party tooling or scripts. PowerShell can make this really easy.

I created a PowerShell script which lists all installed printers and gathers information like the printer name, driver, share name, location and the IP address (the actual IP address, not the portname without the “IP” prefix).

The script outputs all the information to a new Microsoft Excel sheet which looks like this:

Make sure you change the $Printserver value to reflect your print server. By changing this value and running the script on your local workstation, you eliminate the need to install Microsoft Excel on your print server.

# Print server inventory script
# Created by Michel Stevelmans - http://www.michelstevelmans.com

# Set print server name
$Printserver = "PRINTSERVER"

# Create new Excel workbook
$Excel = new-Object -comobject Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()
$Sheet = $Excel.Worksheets.Item(1)
$Sheet.Cells.Item(1,1) = "Printer Name"
$Sheet.Cells.Item(1,2) = "Location"
$Sheet.Cells.Item(1,3) = "Comment"
$Sheet.Cells.Item(1,4) = "IP Address"
$Sheet.Cells.Item(1,5) = "Driver Name"
$Sheet.Cells.Item(1,6) = "Shared"
$Sheet.Cells.Item(1,7) = "Share Name"
$intRow = 2
$WorkBook = $Sheet.UsedRange
$WorkBook.Font.Bold = $True

# Get printer information
$Printers = Get-WMIObject Win32_Printer -computername $Printserver
foreach ($Printer in $Printers)
{
    $Sheet.Cells.Item($intRow, 1) = $Printer.Name
    $Sheet.Cells.Item($intRow, 2) = $Printer.Location
    $Sheet.Cells.Item($intRow, 3) = $Printer.Comment
    $Ports = Get-WmiObject Win32_TcpIpPrinterPort -computername $Printserver
        foreach ($Port in $Ports)
        {
            if ($Port.Name -eq $Printer.PortName)
            {
            $Sheet.Cells.Item($intRow, 4) = $Port.HostAddress
            }
        }
    $Sheet.Cells.Item($intRow, 5) = $Printer.DriverName
    $Sheet.Cells.Item($intRow, 6) = $Printer.Shared
    $Sheet.Cells.Item($intRow, 7) = $Printer.ShareName
    $intRow = $intRow + 1
}

$WorkBook.EntireColumn.AutoFit()
$intRow = $intRow + 1
$Sheet.Cells.Item($intRow,1).Font.Bold = $True
$Sheet.Cells.Item($intRow,1) = "Print server inventory - Created by Michel Stevelmans - http://www.michelstevelmans.com"

  11 Responses to “PowerShell print server inventory script”

  1. Excellent script.. worked great..

  2. Another quick and dirty way to get an inventory is a command line tool called ‘setprinter’

    syntax example ‘setprinter -show “” 6′

    Came in handy recently on a print server with 120 or so printers. pipe it to a text file and get a searchable snapshot of current settings.

  3. What’s the trick to getting this to work? I have tried fully qualified domain name for print server and IP as well. Nothing happens when I run in Powershell. (I have limited scripting knowledge) If I isolate out just the portion that creates the excel document it works fine.
    Local PC is Windows 7, remote is a Windows 2003 server. I have admin privs on both.
    Thanks! This script will be awesome for me if I get it working.

    • Hi Tim,

      If you run the script from the Windows PowerShell ISE (you can find that in your start menu on Windows 7), what is the error message you are getting ?

  4. Thanks your script works like a charm. Could this script be use to run against a Domain Controller to the printers information for the entire Domain. Do you have any recommendation on how to accomplish this task?

    Thanks.

    • Hi Carey,

      Great the script is working out for you!

      The script uses WMI to get most information from the actual print server, so it would never work to get all this information from AD or a domain controller.

      I guess you could make a script that would query AD for a list of print servers and than query each individual print server for the requested information.

  5. Excellent script. I am running it against W2K Server and not getting IP’s back. Any idea what can i do to resolve this issue? Thank you

  6. Nice script, works great. running with ISE and getting info from 2008 servers here.

    how can this be changed to poll multiple servers and create a new worksheet in the same workbook for each print server? I can get it to make the new workbook for each server but not new worksheets.

    Thanks.

  7. Best. PowerShell Script. Ever!

    Worked great – thanks heaps :)

 Leave a Reply

(required)

(required)


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

   
© 2011 Michel Stevelmans Suffusion theme by Sayontan Sinha