In the we appeared on the old-school VBS scripts that can be utilized to handle printers and print operation in all Windows variations, ranging from Windows XP. Today, we’re going to contemplate typical instructions to put in, handle and take away printers, print ports, drivers and queues utilizing PowerShell. These methods of managing printers from PowerShell CLI can be utilized in fashionable working methods – Windows 10 / eight.1 and Windows Server 2019 / 2016 / 2012 R2.
PowerShell module: PrintManagement
Along with the discharge of Windows eight.1 and Windows Server 2012 R2, Microsoft launched a brand new model of PowerShell four.zero (part of Windows Management Framework four.zero), which considerably prolonged the record of Windows-based print server administration cmdlets. You can get the total record of print, driver and print queue administration cmdlets out there in the PrintManagement module on Windows 10 (PowerShell v5) with the next command:
Get-Command –Module PrintManagement
The PrintManagement module embody 22 PowerShell cmdlets for managing printers, drivers, print ports, and queues:
- Add-Printer – add (set up) new printer;
- Add-PrinterDriver – set up new print driver;
- Add-PrinterPort – create native print port;
- Get-PrintConfiguration – show printer configuration;
- Get-Printer – show the record of printers put in on the pc;
- Get-PrinterDriver – show the record of the put in drivers;
- Get-PrinterPort – shows the record of the printer ports;
- Get-PrinterProperty – present printer properties;
- Get-PrintJob – get a listing of printer print jobs;
- Read-PrinterNfcTag – get printer data from the NFC tag;
- Remove-Printer – take away the printer;
- Remove-PrinterDriver — take away the printer driver;
- Remove-PrinterPort – take away the printer port;
- Remove-PrintJob – delete a print job on the printer;
- Rename-Printer – rename the printer;
- Restart-PrintJob – restart the print job;
- Resume-PrintJob – resume the paused print job;
- Set-PrintConfiguration – set the printer configuration;
- Set-Printer – replace the printer configuration;
- Set-PrinterProperty – change printer properties;
- Suspend-PrintJob – droop (pause) the print job;
- Write-PrinterNfcTag – write data into the NFC tag.
To get detailed details about the syntax of any command, use the next command:
Examples of utilizing instructions:
Get-Help < cmdlet_name> -Examples
Let’s have a look at just a few examples of typical printer administration duties utilizing PowerShell in Windows 10.
Adding Printer Drivers to the DriverStore
To record the print drivers which can be put in in the Windows DriverStore:
Then, set up a brand new printer driver in the system, for instance you wish to set up the favored print driver “HP Universal Printing PCL 6”. According to the documentation, the PowerShell command so as to add a print driver must be as follows:
Add-PrinterDriver -Name "HP Universal Printing PCL 6" -InfPath "C:DistrHP-pcl6-x64hpcu118u.inf"
However, when making an attempt to put in a driver this fashion, the next error message seems:
It seems that the driving force from the INF file can solely be put in if it already exists in the DriverStore. It seems that utilizing Add-PrinterDriver command you possibly can’t set up a print driver that isn’t in the Driver Store. To add a driver to the DriverStore, you should utilize:
- the described in the earlier article;
- the utility — pnputil.exe. The command can seems to be as comply with:
pnputil.exe -i -a C:DistrHP-pcl6-x64hpcu118u.inf(installs the precise printer driver) or
pnputil.exe -i -a C:DistrHP-pcl6-x64*.inf(installs all of the drivers discovered in the INF information in the required listing);
- the cmdlet that enables to combine drivers into the offline Windows picture.
After including a printer driver to the driving force repository, it’s best to set up it on the print server:
Add-PrinterDriver -Name "HP Universal Printing PCL 6"
How to Install Printer Using PowerShell
Create an IP port for a community printer (right here you possibly can specify each the IP deal with of the community printer and the title of the distant print server):
Add-PrinterPort -Name "IP_192.168.10.26" -PrinterHostAddress "192.168.10.26"
Before including a brand new IP print port, you possibly can test if it exists:
$portName = "IP_192.168.10.26"
$checkPortExists = Get-Printerport -Name $portname -ErrorAction SilentlyContinue
if (-not $checkPortExists)
With the assistance of the next command, we’ll set up and a brand new printer on the pc:
Add-Printer -Name hp3027_Office1_Buh -DriverName "HP LaserJet M3027 MFP PCL6 Class Driver" -PortName IP_192.168.10.26 -Shared -ShareName "hp3027_1_BUh" –Published
Note: Note that to carry out the identical operation (set up and share a printer) utilizing VBS scripts (Printing Admin scripts), it’s best to carry out two completely different instructions.
After operating these instructions, a brand new shared printer with the title “hp3027_Office1” will seem in the system.
To rename the printer, simply run the command:
Rename-Printer -Name "hp3027_1_Buh" -NewName "hp3027_F1_Salary"
List Installed Printers on a Print Server
Let’s show the total record of printers put in on this laptop:
As you possibly can see, the command reveals the printer title, sort (native or community), driver, print port, whether or not the printer is shared and revealed in the Active Directory.
Most PrintManagement cmdlets can be utilized to view standing and handle printers, drivers and print queues on distant computer systems (print servers). The title of the distant laptop or server is specified as an argument of the –PcName parameter.
You can get details about put in printers on a distant laptop utilizing PowerShell command:
Get-Printer -PcName rome-prnt1 | Format-List Name,DriverName
To show solely a listing of shared printers, use the command:
Get-Printer -PcName rome-prnt1 | the place Shared -eq $true | fl Name
Connecting to a Network Shared Printer with PowerShell
To join the shared printer from the print server, use the command:
Add-Printer -ConnectionName rome-prnt1HP3027
Windows 10 makes use of the latest printer that’s used for printing because the default printer, if you wish to use a set default printer, run the command:
Set-ItemProperty -Path "HKCU:SOFTWAREMicrosoftWindows NTCurrentVersionWindows" -Name "LegacyDefaultPrinterMode" -Value 1 –Force
To set the default printer, you should utilize the next instructions:
$wsnObj = New-Object -COM WScript.Network
How to Remove a Printer Using PowerShell
To take away a printer, you’ll want to run the next PowerShell command:
Remove-Printer -Name "hp3027_L1_O1"
You can take away a particular driver utilizing the Remove-PrinterDriver cmdlet:
Remove-PrinterDriver -Name "HP Universal Printing PCL 6"