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

  • This topic has 3 replies, 4 voices, and was last updated 6 months ago by
    js
    Participant
    .
Viewing 3 reply threads
  • Author
    Posts
    • #171430
      Participant
      Topics: 3
      Replies: 1
      Points: 25
      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: 45
      Points: 243
      Helping Hand
      Rank: Participant

      $Computer = <give any remote server>

      #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: 4
      Points: 38
      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: 28
      Replies: 752
      Points: 2,104
      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.

Viewing 3 reply threads
  • The topic ‘WMI: Get default printer information’ is closed to new replies.