WMI: Get default printer information

Welcome Forums General PowerShell Q&A WMI: Get default printer information

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

js
 
Participant
1 month ago.

  • Author
    Posts
  • #171430

    Participant
    Topics: 1
    Replies: 0
    Points: -5
    Rank: Member

    Hi, all.

    I have a question on querying default printer information by win32_printer.

    When I type it for local computer it display true for the default printer.

    Get-CimInstance -ComputerName localhost -ClassName win32_printer | Select-Object name,Default

    However, When I tried to query for a remote computer, It returned all false for all printers.

    I have no idea why it does not show correct data.

  • #171484

    Participant
    Topics: 0
    Replies: 44
    Points: 235
    Helping Hand
    Rank: Participant

    $Computer =

    #Get Local Printers:

    $Printers = @(Get-WmiObject win32_printer -computername $Computer | Select Name)

    #Get List of Network Printers:

    $Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('currentuser', $Computer)

    $RegKey= $Reg.OpenSubKey('Printers\Settings')

    $Printers += @($RegKey.GetValueNames())

    #Output List of Printers

    Write-Output $Printers | ft -Property @{Name="Printer Name";Expression={$_.Name}} -AutoSize

    #Get Default Printer

    $Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('currentuser', $Computer)

    $RegKey= $Reg.OpenSubKey('Software\Microsoft\Windows NT\CurrentVersion\Windows')

    $DefaultPrinter = $RegKey.GetValue("Device")

    #Output the Default Printer

    Write-Output $DefaultPrinter | ConvertFrom-Csv -Header Name, Provider, Order| Select Name | ft -Property @{Name="Default Printer Name";Expression={$_.Name}} -AutoSize

     

  • #171889

    Participant
    Topics: 1
    Replies: 3
    Points: 32
    Rank: Member

    Hi,

    It may be possible that there is no default printer set on the Remote computer, that is why it is returning all FALSE.

    You can use a filter to only return printer where the DEFAULT attribute is set to TRUE.

    Get-CimInstance -ClassName Win32_Printer -Filter "Default=True"

  • #171952
    js

    Participant
    Topics: 25
    Replies: 678
    Points: 1,629
    Helping Hand
    Rank: Community Hero

    Note that default printer is a per user setting. Also in windows 10, by default keeps changing the default printer to the last printer used.

You must be logged in to reply to this topic.