Author Posts

July 27, 2018 at 6:57 pm

I have been working on a script that allows me to add a network printer to a list of computers from a CSV and that network printer can only be added if credentials are put in when downloading it on a local machine in devices and printers. This is what I have but its not working i'm surely doing something wrong. Could anyone give me guidance on what im doing wrong or what would work better. I am not the GPO admin so this is the route I have to go.

$Credential = Get-Credential
$a = Import-Csv addprinter.csv -Header Computers
Foreach ( $Com in $a ) {{$PrinterPath = "\\domain\name"
$net = new-Object -com WScript.Network
$net.AddWindowsPrinterConnection($PrinterPath)} $Com.Computers -DomainCredential $Credential -Force}

July 27, 2018 at 7:10 pm

Can you be more specific on what you are trying to do? You want to add a network printer, for your user\profile, on multiple computers? Printers are per user, not per system, so this code if it were working would only add the printer for you on the the remote systems. You're asking for assistance, but you haven't specified exactly what issue you are having with the provided code.

July 28, 2018 at 12:50 am

$Credential = Get-Credential
 $a = Import-Csv addprinter.csv -Header Computers
 Foreach ( $Com in $a ) 
   {
     { # < -- Remove this...
      $PrinterPath = "\\domain\name"
      $net = new-Object -com WScript.Network 
      $net.AddWindowsPrinterConnection($PrinterPath)
     } # <-- And this.
     $Com.Computers -DomainCredential $Credential -Force # <-- Remove this.
   } 

You have an extra set of curly braces in your foreach. I have no idea what this line is "$Com.Computers -DomainCredential $Credential -Force" Where did you get that command from?

The new-object cmdlet doesn't have a -credential parameter. Maybe you can try invoking the command?

$Credential = Get-Credential
$a = Import-Csv addprinter.csv -Header Computers
Foreach ( $Com in $a ) 
  {
     $command = {
     $PrinterPath = "\\domain\name"
     $net = New-Object -ComObject WScript.Network
     $net.AddWindowsPrinterConnection($PrinterPath)
     }
     Invoke-Command -ComputerName $com -Credential $Credential -ScriptBlock $command
  } 

Keep in mind that adding a printer in this fashion is specific to the current user. If you want to install the printer for all users you will want to go about creating a new TCP/IP port, and declaring the driver to use, etc.

July 28, 2018 at 2:01 pm

I would do it as a login script. Then you wouldn't need credentials. You can also use "add-printer -connectionname \\server\printer". This type of printer is a pita in my opinion, between things like client-side rendering not cleaning up sid's of deleted profiles, and even not sometimes working the first time a user printer is created, and the little known fact of needing high random ports open on the print server to prevent a 45 second delay in adding the printer. Also, if you start a web browser before setting the default printer, it won't show up in the web browser. If you could do lpr printers instead, I would recommend it.

July 29, 2018 at 11:48 pm

I know this is a powershell site, but your easiest solution is to add the printer with group policy – quick and easy and installs when the user logs on.