2

is there a quick and easy way to install every printer from a print server over a console like PowerShell?

Add-Printer from PowerShell does not support Wildcards.

I tried it with Get-Printer and ForEach

Get-Printer -ComputerName print-server | Select  name > Printers.txt

ForEach ($Printer in Get-Content "Printers.txt")
{
Add-Printer -ConnectionName \\print-server\"$Printer"
}

But I get only the message that the server name is not accessible or invalid. In the powershlel is to see that $Printer didn't replaced with the print name. But when I use Write-Host $Printer this works.

2 Answers 2

3

Instead of piping the printers to a text file and then trying to use them by reading them back in as basic strings, use the properties of the objects returned from Get-Printer.

E.G.:

# Get list of printers from computer "print-server".
$Printers = Get-Printer -ComputerName print-server

# Iterate through the returned list of printers.
ForEach ($Printer in $Printers)
{
    # Check to see if the current printer is shared or not.
    If ($Printer.Shared) {
        # If it's shared, add it by using the print server name and printer name properties of the current printer object.
        Add-Printer -ConnectionName "\\$($Printer.ComputerName)\$($Printer.Name)"
    }
}
7
  • Thank you for your reply. When I execute this script, it never ends and the printer are not getting installed.
    – RogerSik
    May 20, 2016 at 6:20
  • 1
    What you're saying about it running forever is hard to believe, unless there's some kind of transposition error, or some change you've made someplace. ;) If you run just $Printers = Get-Printer -ComputerName print-server and then view $Printers is the list correct? May 20, 2016 at 13:13
  • Yes the list is correct.
    – RogerSik
    May 20, 2016 at 18:33
  • 1
    Did you launch the PowerShell prompt "As Administrator" before running the script? May 20, 2016 at 18:34
  • 2
    @Roger How about opening PS as administrator, running Get-Printer -ComputerName print-server & then when you get that list, run each one-by-one to see if there's a specific printer that hoses it up from the list with the command: Add-Printer -ConnectionName "\\$($Printer.ComputerName)\$($Printer.Name)" just use the values from the Get-Printer -ComputerName print-server command result list... Curious if there's one (or more) that causes a problem and this is why it's hosing up on you. e.g.permission issue, driver issue, etc. I've not tested any of it just adding common thing I'd try. Aug 7, 2016 at 2:33
1

For the script to function correctly a printer on the selected print server will need to have all the necessary permissions added. The printer in question (SelectPrinter) will be used in the script to pull security settings.

(Get-Printer 'SelectPrinter' Full).PermissionSDDL | Out-File 'C:\PrinterSecurity.txt' | $perms = Get-Content 'C:\PrinterSecurity.txt' | Set-Printer '*' -PermissionSDDL $perms. 

This will add the permissions to all existing printers on the print server in question.

Run the command locally from the print server.  

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .