Published: Sep 27, 2022 by Bertland Hope
Installing any Printer with Just PowerShell
Let us take a look at what we need to do when we need to install a printer. It can get a little tricky here, and I will be honest with you, research into this contributed to 87.5%. We will need to manually do the things. I am assuming that you have gone to the printer vendor and got the drivers you need, and we are just using PowerShell to get them onto machines.
Add Drivers
Adding Printer Drivers to the DriverStore
pnputil.exe -i -a \\someNetworkShare\Printers\HP_Color_LaserJet_Pro_MFP_M477fdw\*.inf
Install Driver
After adding a printer driver to the driver repository, you should install it:
Add-PrinterDriver -Name "HP Color LaserJet Pro MFP M477 PCL-6"
Create an IP port
$portName = "IP_192.168.3.9"
$checkPortExists = Get-Printerport -Name $portname -ErrorAction SilentlyContinue
if (-not $checkPortExists) {
Add-PrinterPort -name $portName -PrinterHostAddress "192.168.3.9"
}
Install and Share
Add-Printer -Name hp3027_Office1_Buh -DriverName "HP LaserJet 100 color MFP M175 PCL6" -PortName IP_192.168.2.15 -Shared -ShareName "hp3027_1_BUh" –Published
Install
Add-Printer -Name HP_Color_LaserJet_Pro_MFP_M477_PROJECTS -DriverName "HP Color LaserJet Pro MFP M477 PCL-6" -PortName IP_192.168.3.9
Rename Printer
To rename the printer, just run the command:
Rename-Printer -Name "hp3027_1_Buh" -NewName "hp3027_F1_Salary"
Remove Printer
How to Remove a Printer Using PowerShell? To remove a printer, you need to run the following PowerShell command:
Remove-Printer -Name "hp3027_L1_O1"
Remove Driver
You can remove a specific driver using the Remove-PrinterDriver cmdlet:
Remove-PrinterDriver -Name "HP Universal Printing PCL 6"
Set default printer
Windows 10 uses the latest printer that was used for printing as the default printer. If you want to use a fixed default printer, run the command:
Set-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows" -Name "LegacyDefaultPrinterMode" -Value 1 –Force
To set the default printer, use the following commands:
$wsnObj = New-Object -COM WScript.Network
$wsnObj.SetDefaultPrinter("HP_Color_LaserJet_Pro_MFP_M477_PROJECTS")