10

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

Schlauge
  • 156
  • 1
  • 1
  • 6
  • 2
    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? – jscott Aug 22 '12 at 02:01
  • 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. – Schlauge Aug 22 '12 at 14:27
  • In your scenario what is the difference between "local" and "per computer"? – Mike Aug 24 '12 at 12:30
  • A "Local" printer is a printer assigned to a local port. This might be LPT: or even a TCP-IP port (still network, but directly from PC->Printer). A "per computer" printer is printing through another computer's printer spooler _\\PrintSpooler\P23S_ If the user connect directly to _\\PrintSpooler\P23S_ this is "per user" If I use `rundll32 printui.dll,PrintUIEntry /ga /c\\PCName /n\\PrintSpooler\P23S` It will make the network printer available for all users who login to _PCNAME_ – Schlauge Aug 25 '12 at 01:00
  • I want the same list as the user get in printing menu. (....) – MUY Belgium Jul 22 '15 at 07:26
  • [Using DEVCON to manage devices and drivers](http://www.robvanderwoude.com/devcon.php): scroll down to (downloadable) `ShowPRN.bat` and `ShowPRNT.bat`. However `devcon.exe FindAll =Printer` could suffice. – JosefZ May 17 '16 at 23:17

2 Answers2

6

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
DisplayName
  • 262
  • 4
  • 14
1

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
HackSlash
  • 287
  • 4
  • 15