List ALL Printers using Powershell

99,227

Solution 1

get-shared printers

Get-Printer -ComputerName pc| where Shared -eq $true | fl Name

get not shared printers

 Get-Printer -ComputerName pc | where Shared -eq $false | fl Name

get mapped printers

Get-WMIObject Win32_Printer -ComputerName $env:COMPUTERNAME | where{$_.Name -like “*\\*”} | select sharename,name

get all the printers

Get-WMIObject Win32_Printer -ComputerName $env:COMPUTERNAME

Solution 2

For some strange reason these commands can't see printers mapped in a per user context. As found in a different question, the following code will scan the registry for all user accounts and all list printers for all users.

List all printers for all users.

NOTE: Requires WinRM

param (
    [string]$Comp = "localhost"
)

function ListAllPrinters {
    param (
        [string]$Comp
    )

    Invoke-Command -ComputerName $Comp -ScriptBlock {
        Get-ChildItem Registry::\HKEY_Users | 
        Where-Object { $_.PSChildName -NotMatch ".DEFAULT|S-1-5-18|S-1-5-19|S-1-5-20|_Classes" } | 
        Select-Object -ExpandProperty PSChildName | 
        ForEach-Object { Get-ChildItem Registry::\HKEY_Users\$_\Printers\Connections -Recurse | Select-Object -ExpandProperty Name }
    }
}

# Main
ListAllPrinters $Comp
Share:
99,227

Related videos on Youtube

Schlauge
Author by

Schlauge

Updated on September 18, 2022

Comments

  • Schlauge
    Schlauge almost 2 years

    I'm having issues listing all the printers on a computer using Powershell.

    We have a batch script that will add/remove/list "per computer" printers using PrintUI.

    I can use PrintUI to list the printers.

        rundll32 printui.dll,PrintUIEntry /ge /c"%UNC-NAME%"
    

    This will list just the per computer printers, while...

        Get-WMIObject -Class Win32_Printer -ComputerName $ComputerName
    

    will list the all printers in WMI.

    In the above example I have a system that has 3 printers, when a user is logged in. WMI see's 2 of them, PrintUI see's 1.

    I'm boggled how I can list them ALL! So that I can script auditing/adding/removing both "per computer" and "local" printers

    • jscott
      jscott almost 12 years
      Do you mean "both 'per computer' and 'per user' printers"? Users may add their own printers in addition to the per-computer ones. Do you need to iterate all user profiles on the computer, or just the current active profile?
    • Schlauge
      Schlauge almost 12 years
      I know I can't see "per user" printers, but I'm looking for all printers that ALL users would see on a computer. "per computer" and "local" Ideally, I would be running this remotely, so my tech does not have to go to each computer to add/remove printers. If a user adds their own to their profile, I don't care. But I want to make sure we can see what printers are available within one view.
    • Mike
      Mike almost 12 years
      In your scenario what is the difference between "local" and "per computer"?
    • JosefZ
      JosefZ about 8 years
      Using DEVCON to manage devices and drivers: scroll down to (downloadable) ShowPRN.bat and ShowPRNT.bat. However devcon.exe FindAll =Printer could suffice.
  • Dmitry Kazakov
    Dmitry Kazakov almost 8 years
    Everything is correct, but check double quotes in get mapped printers method while you copy-paste the code.
  • MUY Belgium
    MUY Belgium almost 6 years
    Do not list printer owned by other users...