If you have to add printers frequently, for example when managing the print server, it can be more efficient to do this with PowerShell instead of using the MMC-based print management. Consistent automation of this process is only prevented by downloading and unpacking the drivers.
Graphic print management is also able to administer printers on remote computers. This also includes the option of setting up new ports, adding drivers and creating printers.
Instead of clicking through the GUI of the MMC tool, you can use PowerShell. All cmdlets for the required steps support the parameter ComputerName, so you can easily create printers remotely.
Load drivers on Windows Server 2019
A hurdle turns out, however, that Windows Server 2019 contains practically no printer drivers. If you use this version of the operating system for a print server, you first have to bring the required drivers to the system.
The source for printer drivers will either be the Microsoft Update Catalog or the website of the hardware manufacturer. Microsoft’s catalog is intended for interactive use and therefore blocks a download via script or command line.
A consistent automation of the printer installation is also opposed by the fact that PowerShell does not have the means to unpack the .cab file with the drivers and to transfer them to the Driver Store.
To do this, you have to use conventional CLI tools. But this also applies if you prefer the interactive variant via the graphic printer management.
Copy and unzip drivers to the server
In the first step after downloading the driver package, you copy it to the remote print server. If this runs under Server Core, the Admin Center proves to be helpful for this task.
Then open a remote session with Enter-PSSession and change to the directory in which the .cab file is located. There you unpack them with the expand utility, in the following example in the subdirectory driver:
expand.exe. drivers_15de7944aba1cf37d7e561875c43a8e32e1180bd.cab -F: *. driver
The next step is to take the exact name of the printer from the .inf file, which you will then need to add the driver. To do this, you can search for a part of the character string with Select-String:
Get-Content. Prnsacl1.inf | Select string "ML-3300"
In this example we want to find out the full name of the Samsung ML-3300 series printer.
Transfer the printer driver to the store
Then transfer the extracted drivers to the local store:
pnputil.exe -a prnsacl1.inf
Only now does PowerShell come into play. Since we are already in a remote session here, we can run the cmdlets locally and need the parameter ComputerName Not.
Add printer driver
To add the printer driver first, you need the name above:
Add-PrinterDriver name "Samsung ML-3300 Series Class Driver"
you can see for yourself whether the driver is now available in the system.
Create connection for network printer
As is well known, every printer needs a connection. If the desired one for the respective printer does not yet exist, you can now create it. If you want to make sure beforehand whether a certain port already exists, then shows
this at. For a network printer you could create a TCP / IP port like this:
Add-PrinterPort -Name "IP_192.168.0.99" -PrinterHostAddress "192.168.0.99"
Add and configure printer
Now the prerequisites are given to add the printer:
Add-Printer -Name "Samsung ML-3310" -DriverName "Samsung ML-3300 Series Class Driver" `
As you can see, you need the name of the driver and the port you created earlier. The name for the printer can be freely assigned. If you want to create a larger number of printers right away, it makes sense to read out your data from a CSV file and transfer it to Add-Printer.
As a rule, you will want to share the printer in the network and register it in the Active Directory. You would have done that via the corresponding parameters of Add printer can do, but is easy with Set printer catch up:
Set-Printer -Name "Samsung ML-3310" -Location "Redaktion" -Published $ true -Shared $ true
This call releases the printer under its name because of the parameter ShareName was not specified. Published enters the printer in the Active Directory. In addition, Location specifies the location where the printer is located, typically that is the name of a department, a room number or the like.
With Comment you could add additional information. In addition, the time span (StartTime and UntilTime) during which a printer is available.