Add-printer remotely

This topic contains 9 replies, has 5 voices, and was last updated by  JB Lewis 1 week, 5 days ago.

  • Author
    Posts
  • #28030

    Windows LiveUser103
    Participant

    I am trying to run this command remotely through invoke-command and pssessions, but it does not work. Locally I am able to add-printer and remove-printer, but the exact same commands don't work remotely. I get an error that the printer server or name may be incorrect. Any ideas?

  • #28031

    Don Jones
    Keymaster

    Two possibilities.

    One, when you remote into a machine, you don't spin up a full user profile. It's more like connecting to a network share. So it could be running into a problem if it's expecting a user profile.

    Second, when your credentials are delegated to the remote machine, it can only use them for local resources. If it needs to connect to a print server, then it's likely failing if the print server won't accept an anonymous connection. This is called the "second hop" problem, and it's discussed at some length in "Secrets of PowerShell Remoting" (free from the Resources/eBooks menu here), along with workarounds.

  • #28032

    Greg Altman
    Participant

    Depending on the version of PowerShell, I have had success with

        #Add Ports
        Add-PrinterPort -Name $PrinterPort -PrinterHostAddress $PrinterIP -ComputerName $Computer   
    # Add Printers
        Add-Printer -computername $Computer -name $PrinterName -PortName $PrinterName-DriverName "HP Universal Printing PCL 6"
     

    That assumes the driver is on the client PC already.

    Also note this is NOT run thru a PSSession or Invoke-Command. The Add-Printer and Add-Printerport have a -computername parameter.

  • #28034

    Windows LiveUser103
    Participant

    That worked!

  • #28036

    Windows LiveUser103
    Participant

    Greg,

    These commands work I am able to remotely add and remove printers. If I want to use this to add printers to multiple computer at once the variable doesn't work. Example $computer = user1,user2. This gives me a failure.

  • #28037

    Don Jones
    Keymaster

    The -ComputerName parameter of Add-Printer only accepts a single computer name.

    As in the help file:

    -ComputerName String

    Not:

    -ComputerName String[]

  • #28039

    Windows LiveUser103
    Participant

    Thank you Don.

  • #28044

    Greg Altman
    Participant

    yep, the quick and easy way is :

    $Computers = 'PC1','PC2','PC3'
    ForEach ($Computer in $Computers) {
            #Add Ports
           Add-PrinterPort -Name $PrinterPort -PrinterHostAddress $PrinterIP -ComputerName $Computer   
           # Add Printers
           Add-Printer -computername $Computer -name $PrinterName -PortName $PrinterName-DriverName "HP Universal Printing PCL 6"
    }
     
  • #79363

    Brandon
    Participant

    Is there a way to reference a specific share with printer drivers located in it for the printer rather than using the ones from the machine?

    • #79456

      JB Lewis
      Participant

      I believe you'd then be looking at Add-PrinterDriver, you can provide a path to an INF file. Unfortunately, the help for Add-PrinterDriver is somewhat lacking. You need to install the print(er) driver, before you can add a printer that uses that driver.

      JBLewis

You must be logged in to reply to this topic.