WMI: Get default printer information

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.

$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

 

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”

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.