Drucker per Powershell Managen hinzugefügt
@@ -0,0 +1,161 @@
|
||||
## Managing Printers and Drivers on Windows with PowerShell
|
||||
|
||||
With PowerShell, you can automate common printer and printer driver management tasks in Windows. This guide explains how to create, delete, or share a printer from the PowerShell console; set a default printer; map a network printer; install or remove printer drivers; and manage local ports and print queues.
|
||||
|
||||
|
||||
|
||||
The built-in PrintManagement PowerShell module includes 22 cmdlets for managing printers, drivers, print ports, and queues:
|
||||
|
||||
`Get-Command –Module PrintManagement
|
||||
`
|
||||
|
||||
Add-Printer – add (install) a new printer;
|
||||
Add-PrinterDriver – install a new printer driver;
|
||||
Add-PrinterPort – create a local print port;
|
||||
Get-PrintConfiguration – display the printer configuration;
|
||||
Get-Printer – list the printers installed on a computer;
|
||||
Get-PrinterDriver – list the available printer drivers;
|
||||
Get-PrinterPort – show the printer ports;
|
||||
Get-PrinterProperty – show the printer properties;
|
||||
Get-PrintJob – list the print tasks in the queue;
|
||||
Read-PrinterNfcTag – get printer information from the NFC tag;
|
||||
Remove-Printer – remove the printer;
|
||||
Remove-PrinterDriver — remove the printer driver;
|
||||
Remove-PrinterPort – remove 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 – update the printer configuration;
|
||||
Set-PrinterProperty – change printer properties;
|
||||
Suspend-PrintJob – suspend (pause) the print job;
|
||||
Write-PrinterNfcTag – write information into the NFC tag.
|
||||
|
||||
|
||||
### Adding Printer Drivers to the DriverStore
|
||||
|
||||
The PrintManagement module has the Add-PrinterDriver cmdlet, which allows install a printer driver from an INF file. In fact, this cmdlet only allows adding drivers to an offline Windows image (just like the Add-WindowsDriver command, which lets you integrate drivers into offline Windows images).
|
||||
|
||||
To install a printer driver from an INF file, use the pnputil console command. Download the drivers for your printer model from the vendor’s website and extract them to a local folder. Then install the driver:
|
||||
|
||||
`pnputil.exe -i -a "C:\drivers\KYOCERA\KyoClassicUniversalPCL6\OEMsetup.inf"
|
||||
`
|
||||
|
||||
Once the driver has been installed in the Windows Driver Store, it must be added to the list of available drivers for the print server:
|
||||
|
||||
`Add-PrinterDriver -Name "Kyocera Classic Universaldriver PCL6"
|
||||
`
|
||||
|
||||
Copy the exact name of the printer driver from the INF file.
|
||||
List available print drivers:
|
||||
|
||||
`Get-PrinterDriver
|
||||
`
|
||||
### How to Install Printer with PowerShell
|
||||
Before creating a new printer, you must add a printer port. This can be a local port or it can be a network port (to send print jobs to a remote printer over the network). For example:
|
||||
`Add-PrinterPort -Name "LocalPort:" -ErrorAction -Verbose
|
||||
`
|
||||
Or specify the remote printer IP or print server name as the PrinterHostAddress.
|
||||
|
||||
`Add-PrinterPort -Name "IP_192.168.10.26" -PrinterHostAddress "192.168.10.26"
|
||||
`
|
||||
To create a new printer in Windows, specify the printer name, driver, and port:
|
||||
|
||||
`Add-Printer -Name "Ricoh IM 2702" -DriverName "Kyocera Classic Universaldriver PCL6" -PortName USB001 -Verbose
|
||||
`
|
||||
|
||||
Check that the new printer appears in the Control Panel and Settings app.
|
||||
|
||||
To rename the printer:
|
||||
|
||||
`Rename-Printer -Name "Ricoh IM 2702" -NewName "Ricoh_2702"
|
||||
`
|
||||
To share a new printer over the network:
|
||||
|
||||
`Set-Printer -Name "Ricoh IM 2702" -Shared $True -ShareName "Ricoh_2702"
|
||||
`
|
||||
Disable printer sharing:
|
||||
|
||||
`Set-Printer -Name "Ricoh IM 2702" -Shared $False
|
||||
`
|
||||
### List Printers on a Print Server Using PowerShell
|
||||
List the printers installed on a computer:
|
||||
|
||||
`Get-Printer
|
||||
`
|
||||
The command returns the printer names, types (local or network), driver, print port, whether the printer is shared, and whether it is published in Active Directory.
|
||||
|
||||
Most of the cmdlets in the PrintManagement module can be used to manage printers on remote computers (by using the _-ComputerName_ parameter).
|
||||
|
||||
View a list of printers installed on a remote computer (print server):
|
||||
|
||||
`Get-Printer -ComputerName rome-prnt1 | Format-List Name,DriverName
|
||||
`
|
||||
List shared printers on a computer:
|
||||
|
||||
`Get-Printer -ComputerName rome-prnt1 | where Shared -eq $true | fl Name
|
||||
`
|
||||
Get printers that have duplex printing support:
|
||||
|
||||
`Get-Printer | ForEach-Object { Get-PrintConfiguration -PrinterName $_.Name } | Where-Object { $_.DuplexingMode -ne "OneSided" }
|
||||
`
|
||||
|
||||
List all the color printers on a computer:
|
||||
|
||||
`Get-Printer | ForEach-Object { Get-PrintConfiguration -PrinterName $_.Name } | where {$_.Color -eq $True}
|
||||
`
|
||||
Enable color printing mode for a printer:
|
||||
|
||||
`Get-Printer 'HP Color LaserJet 150nw' | Set-PrintConfiguration -Color $true
|
||||
`
|
||||
Connect a Network Shared Printer with PowerShell
|
||||
To connect a shared printer from a print server to a computer:
|
||||
|
||||
`Add-Printer -ConnectionName \\rome-prnt1\HP3027
|
||||
`
|
||||
List the network printers connected to a computer:
|
||||
|
||||
`Get-Printer | ?{$_.type -eq 'Connection'}
|
||||
`
|
||||
Remove a specific network printer connection:
|
||||
|
||||
`Get-Printer -name \\rome-prnt1\HP3027| Remove-Printer -force
|
||||
`
|
||||
Remove all mapped network printers from your computer:
|
||||
|
||||
`Get-Printer | ?{$_.type -eq 'Connection'} | Remove-Printer
|
||||
`
|
||||
|
||||
### Set a Default Printer on Windows
|
||||
[Windows automatically sets the default printer](https://woshub.com/change-default-printer-windows/) to the last printer that the user successfully printed to. To prevent Windows from reassigning the default printer, create the LegacyDefaultPrinterMode registry parameter:
|
||||
|
||||
`Set-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows" -Name "LegacyDefaultPrinterMode" -Value 1 –Force
|
||||
`
|
||||
Then use the following commands to set the fixed default printer:
|
||||
|
||||
```
|
||||
$Printer = Get-CimInstance -Class Win32_Printer -Filter "Name='Ricoh IM 2702'"
|
||||
Invoke-CimMethod -InputObject $Printer -MethodName SetDefaultPrinter
|
||||
```
|
||||
|
||||
|
||||
|
||||
### How to Remove Printer with PowerShell
|
||||
To remove a printer, use the command:
|
||||
|
||||
`Remove-Printer -Name "HP LaserJet M1530"
|
||||
`
|
||||
You can then remove the printer driver from the print server:
|
||||
|
||||
`Remove-PrinterDriver -Name "HP Universal Printing PCL 6"
|
||||
`
|
||||
Send a test page for printing:
|
||||
|
||||
`Invoke-CimMethod -MethodName printtestpage -InputObject (Get-CimInstance win32_printer | Where-Object Name -eq "HP LaserJet M1530")
|
||||
`
|
||||
Clear the printer queue:
|
||||
|
||||
`Get-Printer -Name "HP LaserJet M1530" | Get-PrintJob | Remove-PrintJob
|
||||
`
|
||||
|
||||
Reference in New Issue
Block a user