Get-Printer question

Welcome Forums General PowerShell Q&A Get-Printer question

This topic contains 6 replies, has 3 voices, and was last updated by

 
Participant
1 year ago.

  • Author
    Posts
  • #89186

    Participant
    Points: 0
    Rank: Member

    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!

  • #89189

    Participant
    Points: 23
    Rank: Member

    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
    }
    
    • #89195

      Participant
      Points: 0
      Rank: Member

      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?

    • #89197

      Participant
      Points: 23
      Rank: Member

      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
      }
      
    • #89198

      Participant
      Points: 0
      Rank: Member

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

  • #89233

    Participant
    Points: 0
    Rank: Member

    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

    • #89267

      Participant
      Points: 0
      Rank: Member

      Thanks Richard!

The topic ‘Get-Printer question’ is closed to new replies.