Author Posts

December 14, 2017 at 3:48 am

Hi All,
I am relatively new to Powershell. I am trying to write a script that will give me all printers with errors in their print queues. In addition I need to pull them from multiple servers. So far I have the following:

get-printer -computername "servername1", "servername2", "servername3"
| where printerstatus -eq Error | Format-list Name, Jobcount

I keep getting an error related to the -computername parameter. No matter what I try with multiple server entries it does not work. It DOES work with a single server entry.

Any help is appreciated!

December 14, 2017 at 5:51 am

Running 'Get-Help Get-Printer -Full' will show you that the ComputerName parameter only accepts one string.
You will need to create a foreach loop and pass the computers in one at a time.

$computerName = "servername1", "servername2", "servername3"

foreach ($computer in $computerName) {

    Get-Printer -ComputerName $computer | where printerstatus -eq Error | Format-list Name, Jobcount
}

December 14, 2017 at 6:13 am

Thank You MUCH John! I notice there is no object for servername with Get-Printer. Do you know of a way to pull in the servername for each printer's output?

December 14, 2017 at 6:22 am

Using your example, if you are just looking for the computer name to be part of the output you just need to add the ComputerName property to Format-List.

$computerName = "servername1", "servername2", "servername3"

foreach ($computer in $computerName) {

    Get-Printer -ComputerName $computer | where printerstatus -eq Error | Format-list ComputerName, Name, Jobcount
}

December 14, 2017 at 6:39 am

Thank You! Very much Appreciate it John! Enjoying learning Powershell and am extremely grateful for the support of the community!

December 14, 2017 at 3:31 pm

Get-Printer can accept a collection of CimSessions so you could do something like

$cs = New-CimSession -ComputerName "servername1", "servername2", "servername3"
Get-Printer -CimSession $cs

You could even possibly do

Get-Printer -CimSession "servername1", "servername2", "servername3"

As CimSession will often take list of computer names and automatically create and dispose of the sessions