none
Installing printers drivers from power shell on win client RRS feed

  • Question

  • Hi,

    I am using a powershell script to install printer drivers from our print server. I am getting a error.

    Sript :-

    (New-Object -ComObject WScript.Network).AddWindowsPrinterConnection("\\ptprint\pg1-b")

    (New-Object -ComObject WScript.Network).SetDefaultPrinter('\\ptprint\pg1-b')

    PTPRINT is our print server and pg1-b is printer shared name.

    Error : -

    Exception calling "AddWindowsPrinterConnection" with "1" argument(s): "The I/O operation has been aborted because of
    either a thread exit or an application request. (Exception from HRESULT: 0x800703E3)"
    At C:\Users\amitkumar_patil\Desktop\addprinter.ps1:4 char:1
    + (New-Object -ComObject WScript.Network).AddWindowsPrinterConnection("\\ptprint\p ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : ComMethodTargetInvocation

    Exception calling "SetDefaultPrinter" with "1" argument(s): "There is no printer called "\\ptprint\pg1-b"."
    At C:\Users\amitkumar_patil\Desktop\addprinter.ps1:10 char:1
    + (New-Object -ComObject WScript.Network).SetDefaultPrinter('\\ptprint\pg1-b')
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : ComMethodTargetInvocation

    1. How to solve this ?

    2. Is my way to install drivers is incorrect via power shell ?

    Wednesday, June 11, 2014 10:13 AM

Answers

  • You are not installing a printer you are connecting to a shared printer.

    Look at your error.  Either you have a typo or you do not have permissions.

    Try this at a prompt one line at a time:

    $nw=New-Object -ComObject WScript.Network
    $nw.AddWindowsPrinterConnection('\\ptprint\pg1-b')
    $nw.SetDefaultPrinter('\\ptprint\pg1-b')
    


    ¯\_(ツ)_/¯

    Wednesday, June 11, 2014 10:47 AM

All replies

  • You are not installing a printer you are connecting to a shared printer.

    Look at your error.  Either you have a typo or you do not have permissions.

    Try this at a prompt one line at a time:

    $nw=New-Object -ComObject WScript.Network
    $nw.AddWindowsPrinterConnection('\\ptprint\pg1-b')
    $nw.SetDefaultPrinter('\\ptprint\pg1-b')
    


    ¯\_(ツ)_/¯

    Wednesday, June 11, 2014 10:47 AM
  • This is probably even safer:

    $server='ptprint'
    $printer='pg1-b'
    if(gwmi win32_printer -ComputerName $server -filter "Name='$printer'"){
         $nw=New-Object -ComObject WScript.Network
         $nw.AddWindowsPrinterConnection("\\$server\$printer")
         $nw.SetDefaultPrinter("\\$server\$printer")
    }else{
    'printer not available'
    }


    ¯\_(ツ)_/¯


    • Edited by jrv Wednesday, June 11, 2014 10:55 AM
    Wednesday, June 11, 2014 10:55 AM
  • Thanks very much. It worked for me.

    Just wanted to now does it download and install drivers by connecting to printer from print server ?

    Because it took 5 mins to show printer in control panel.

    Thursday, June 12, 2014 11:00 AM
  • For questions about basic Windows functionality you should post in the Microsoft users support forum.

    The Windows print spooler is one of the oldest parts for Windows NT.  Its use an capabilities are one thing that modern computer platforms do well.  How this works is quite technical and complex.  There are books and forums dedicated to this technology.  Teaching this basic technology is beyond the scope of this forum.

    I suggest starting with the MCP courseware on Windows workstation. It will help you with the basics.


    ¯\_(ツ)_/¯

    Thursday, June 12, 2014 1:30 PM
  • Thanks Sir.

    Saturday, June 14, 2014 12:31 PM