-1

AIM : To export Network Printer from one Windows 10 machine to an output file and using that output file import it to another Windows 10 machine on the same network.

Research work:

The following Powershell cmd shows the Mapped printers for a user:

cmdlet 1)

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

NOTE: The above cmd does not show the DriverName which is a critical parameter for the next command

The command that I am planning to use to import the Network Printer:

cmdlet 2)

Syntax:

rundll32 printui.dll,PrintUIEntry /Xs /n\SERVER\PRINTERSHARENAME DriverName "Lexmark C752 PS3"

since I didnt have the drivername , I tried to run it anyways as the driver is already installed on the second Windows 10 box.

rundll32 printui.dll,PrintUIEntry /Xs /n"\tdr09\AlphaIT(prtq3) KONICA MINOLTA C550i"

But I get error after running the cmd:

===========================================================================

[Window Title] Printers

[Main Instruction] The arguments are invalid.

[OK]

===========================================================================

Problem:

1) The cmdlet 1 doesnt provide the DriverName so the cmdlet 2 is failing with the above error.

=======================================================================

Method 2 Based on feedback from @Massimo

I tried to use the following command :

get-printer | where{$_.Name -like "\"} | Format-Table -AutoSize enter image description here

The Output looks like this:

Name ComputerName Type DriverName PortName Shared Publ ishe d


\trq02\AXEIT(ptq2) KONICA MINOLTA C550i ptq02 Connection KONICA MINOLTA C650iSeries 10.246.0.173 True F...

I can pipe it out to a text file but how can I make PowerShell read this file and add the Printer.

NOTE: If I run the following cmd manually then Printer add works fine.

add-printer "\trq02\AXEIT(ptq2) KONICA MINOLTA C550i"

Guru
  • 1
  • 1

1 Answers1

3

Why are you even bothering with WMI and rundll32?

You should use the native PowerShell commands Get-Printer and Add-Printer.


Example:

On the first computer, use:

Get-Printer | where {$_.Type -eq 'Connection'} | Export-Csv -Path 'C:\Printers.csv'

Copy the file to the second computer and use:

$printers = Import-Csv -Path 'C:\Printers.csv'

foreach($printer in $printers)
{
    Add-Printer -ConnectionName ($printer.Name)
}
Massimo
  • 70,200
  • 57
  • 200
  • 323
  • I tried to use the following command : get-printer | where{$_.Name -like "*\\*"} | Format-Table -AutoSize The Output looks like this: – Guru Feb 28 '23 at 06:22
  • Made a little progress based on the suggestion.... now trying to find out how to read the txt file output and add the printer. I have updated some of it in the Question. Greatly appreciate if you can help with reading the Output of the cmd and feeding it to the next cmdline for adding the Printer. – Guru Feb 28 '23 at 06:34
  • Don't use `| Format-Table`, this is only for displaying the output on a screen; it will format the output as table and in the process will turn the output into plain text, making it unreadable to further commands. You should export the output from the first command to a CSV file using `Export-Csv` and then read it in the destination system using `Import-Csv`; this will build an actual in-memory table from which you can read columns, rows and values to feed into the second command. – Massimo Feb 28 '23 at 07:45
  • Sorry I azm not that good with powershell.... How do I read this table exclusively for the printer name and make it run add-printer "\trq02\AXEIT(ptq2) KONICA MINOLTA C550i" – Guru Mar 02 '23 at 06:33
  • @Guru see added example. – Massimo Mar 02 '23 at 12:02
  • Thanks @Massimo ... It works very well. Have a great day!!!!! – Guru Mar 18 '23 at 06:01