2

I've been trying to install a network printer using Powershell on Windows 7 so that I can automate the setup of our development machines using Puppet. I found a couple of instructions around but none seem to work in my case.

One of them uses Add-Printer, which is only available on Windows 8, and the other ones don't seem to do anything:

# First one I tried
PS> $net = New-Object -Com WScript.Network
PS> $net.AddWindowsPrinterConnection('\\server\name')

# Second one:
PS> $printer=[WMIClass]"\\.\root\cimv2:Win32_Printer"
PS> $printer.AddPrinterConnection("\\server\name")

Am I missing something? Or is there another way of achieving this?

1

This should work for you.

# This function maps printers from an array
function Map-Printers($Printers) {
  # Loop over the array
  foreach ($Printer in $Printers) {
    # Map the printer
    (New-Object -ComObject WScript.Network).AddWindowsPrinterConnection($Printer)
  }
}

# Define a printer array
$Printers = @("\\print-server.domain.tld\printer1", "\\print-server.domain.tld\printer2")

# Call our map printers function and pass in the printers array.
Map-Printers -Printers $Printers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.