Score:-1

Add Network Printer using command /Powershell after exporting it from One Machine to Another Windows 10/11

bd flag

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"

Score:3
ng flag

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)
}
Guru avatar
bd flag
I tried to use the following command : get-printer | where{$_.Name -like "*\\*"} | Format-Table -AutoSize The Output looks like this:
Guru avatar
bd flag
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.
Massimo avatar
ng flag
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.
Guru avatar
bd flag
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"
Massimo avatar
ng flag
@Guru see added example.
Guru avatar
bd flag
Thanks @Massimo ... It works very well. Have a great day!!!!!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.