Drucker per Powershell Managen aktualisiert
@@ -6,8 +6,7 @@ With PowerShell, you can automate common printer and printer driver management t
|
|||||||
|
|
||||||
The built-in PrintManagement PowerShell module includes 22 cmdlets for managing printers, drivers, print ports, and queues:
|
The built-in PrintManagement PowerShell module includes 22 cmdlets for managing printers, drivers, print ports, and queues:
|
||||||
|
|
||||||
`Get-Command –Module PrintManagement
|
`Get-Command –Module PrintManagement`
|
||||||
`
|
|
||||||
|
|
||||||
```
|
```
|
||||||
Add-Printer – add (install) a new printer;
|
Add-Printer – add (install) a new printer;
|
||||||
@@ -42,61 +41,51 @@ The PrintManagement module has the Add-PrinterDriver cmdlet, which allows instal
|
|||||||
|
|
||||||
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:
|
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"
|
`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:
|
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"
|
`Add-PrinterDriver -Name "Kyocera Classic Universaldriver PCL6"`
|
||||||
`
|
|
||||||
|
|
||||||
Copy the exact name of the printer driver from the INF file.
|
Copy the exact name of the printer driver from the INF file.
|
||||||
|
|
||||||
|
|
||||||
List available print drivers:
|
List available print drivers:
|
||||||
|
|
||||||
`Get-PrinterDriver
|
`Get-PrinterDriver`
|
||||||
`
|
|
||||||
|
|
||||||
|
|
||||||
### How to Install Printer with PowerShell
|
### 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:
|
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
|
`Add-PrinterPort -Name "LocalPort:" -ErrorAction -Verbose`
|
||||||
`
|
|
||||||
|
|
||||||
Or specify the remote printer IP or print server name as the PrinterHostAddress.
|
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"
|
`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:
|
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
|
`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.
|
Check that the new printer appears in the Control Panel and Settings app.
|
||||||
|
|
||||||
To rename the printer:
|
To rename the printer:
|
||||||
|
|
||||||
`Rename-Printer -Name "Ricoh IM 2702" -NewName "Ricoh_2702"
|
`Rename-Printer -Name "Ricoh IM 2702" -NewName "Ricoh_2702"`
|
||||||
`
|
|
||||||
|
|
||||||
To share a new printer over the network:
|
To share a new printer over the network:
|
||||||
|
|
||||||
`Set-Printer -Name "Ricoh IM 2702" -Shared $True -ShareName "Ricoh_2702"
|
`Set-Printer -Name "Ricoh IM 2702" -Shared $True -ShareName "Ricoh_2702"`
|
||||||
`
|
|
||||||
|
|
||||||
Disable printer sharing:
|
Disable printer sharing:
|
||||||
|
|
||||||
`Set-Printer -Name "Ricoh IM 2702" -Shared $False
|
`Set-Printer -Name "Ricoh IM 2702" -Shared $False`
|
||||||
`
|
|
||||||
|
|
||||||
|
|
||||||
### List Printers on a Print Server Using PowerShell
|
### List Printers on a Print Server Using PowerShell
|
||||||
List the printers installed on a computer:
|
List the printers installed on a computer:
|
||||||
|
|
||||||
`Get-Printer
|
`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.
|
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.
|
||||||
|
|
||||||
@@ -104,55 +93,45 @@ Most of the cmdlets in the PrintManagement module can be used to manage printers
|
|||||||
|
|
||||||
View a list of printers installed on a remote computer (print server):
|
View a list of printers installed on a remote computer (print server):
|
||||||
|
|
||||||
`Get-Printer -ComputerName rome-prnt1 | Format-List Name,DriverName
|
`Get-Printer -ComputerName rome-prnt1 | Format-List Name,DriverName`
|
||||||
`
|
|
||||||
|
|
||||||
List shared printers on a computer:
|
List shared printers on a computer:
|
||||||
|
|
||||||
`Get-Printer -ComputerName rome-prnt1 | where Shared -eq $true | fl Name
|
`Get-Printer -ComputerName rome-prnt1 | where Shared -eq $true | fl Name`
|
||||||
`
|
|
||||||
|
|
||||||
Get printers that have duplex printing support:
|
Get printers that have duplex printing support:
|
||||||
|
|
||||||
`Get-Printer | ForEach-Object { Get-PrintConfiguration -PrinterName $_.Name } | Where-Object { $_.DuplexingMode -ne "OneSided" }
|
`Get-Printer | ForEach-Object { Get-PrintConfiguration -PrinterName $_.Name } | Where-Object { $_.DuplexingMode -ne "OneSided" }`
|
||||||
`
|
|
||||||
|
|
||||||
List all the color printers on a computer:
|
List all the color printers on a computer:
|
||||||
|
|
||||||
`Get-Printer | ForEach-Object { Get-PrintConfiguration -PrinterName $_.Name } | where {$_.Color -eq $True}
|
`Get-Printer | ForEach-Object { Get-PrintConfiguration -PrinterName $_.Name } | where {$_.Color -eq $True}`
|
||||||
`
|
|
||||||
|
|
||||||
Enable color printing mode for a printer:
|
Enable color printing mode for a printer:
|
||||||
|
|
||||||
`Get-Printer 'HP Color LaserJet 150nw' | Set-PrintConfiguration -Color $true
|
`Get-Printer 'HP Color LaserJet 150nw' | Set-PrintConfiguration -Color $true`
|
||||||
`
|
|
||||||
|
|
||||||
Connect a Network Shared Printer with PowerShell
|
Connect a Network Shared Printer with PowerShell
|
||||||
To connect a shared printer from a print server to a computer:
|
To connect a shared printer from a print server to a computer:
|
||||||
|
|
||||||
`Add-Printer -ConnectionName \\rome-prnt1\HP3027
|
`Add-Printer -ConnectionName \\rome-prnt1\HP3027`
|
||||||
`
|
|
||||||
|
|
||||||
List the network printers connected to a computer:
|
List the network printers connected to a computer:
|
||||||
|
|
||||||
`Get-Printer | ?{$_.type -eq 'Connection'}
|
`Get-Printer | ?{$_.type -eq 'Connection'}`
|
||||||
`
|
|
||||||
|
|
||||||
Remove a specific network printer connection:
|
Remove a specific network printer connection:
|
||||||
|
|
||||||
`Get-Printer -name \\rome-prnt1\HP3027| Remove-Printer -force
|
`Get-Printer -name \\rome-prnt1\HP3027| Remove-Printer -force`
|
||||||
`
|
|
||||||
|
|
||||||
Remove all mapped network printers from your computer:
|
Remove all mapped network printers from your computer:
|
||||||
|
|
||||||
`Get-Printer | ?{$_.type -eq 'Connection'} | Remove-Printer
|
`Get-Printer | ?{$_.type -eq 'Connection'} | Remove-Printer`
|
||||||
`
|
|
||||||
|
|
||||||
### Set a Default Printer on Windows
|
### Set a Default Printer on Windows
|
||||||
Windows automatically sets the default printer to the last printer that the user successfully printed to. To prevent Windows from reassigning the default printer, create the LegacyDefaultPrinterMode registry parameter:
|
Windows automatically sets the default printer 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
|
`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:
|
Then use the following commands to set the fixed default printer:
|
||||||
|
|
||||||
@@ -165,21 +144,16 @@ Invoke-CimMethod -InputObject $Printer -MethodName SetDefaultPrinter
|
|||||||
### How to Remove Printer with PowerShell
|
### How to Remove Printer with PowerShell
|
||||||
To remove a printer, use the command:
|
To remove a printer, use the command:
|
||||||
|
|
||||||
`Remove-Printer -Name "HP LaserJet M1530"
|
`Remove-Printer -Name "HP LaserJet M1530"`
|
||||||
`
|
|
||||||
|
|
||||||
You can then remove the printer driver from the print server:
|
You can then remove the printer driver from the print server:
|
||||||
|
|
||||||
`Remove-PrinterDriver -Name "HP Universal Printing PCL 6"
|
`Remove-PrinterDriver -Name "HP Universal Printing PCL 6"`
|
||||||
`
|
|
||||||
|
|
||||||
Send a test page for printing:
|
Send a test page for printing:
|
||||||
|
|
||||||
`Invoke-CimMethod -MethodName printtestpage -InputObject (Get-CimInstance win32_printer | Where-Object Name -eq "HP LaserJet M1530")
|
`Invoke-CimMethod -MethodName printtestpage -InputObject (Get-CimInstance win32_printer | Where-Object Name -eq "HP LaserJet M1530")`
|
||||||
`
|
|
||||||
|
|
||||||
Clear the printer queue:
|
Clear the printer queue:
|
||||||
|
`Get-Printer -Name "HP LaserJet M1530" | Get-PrintJob | Remove-PrintJob`
|
||||||
`Get-Printer -Name "HP LaserJet M1530" | Get-PrintJob | Remove-PrintJob
|
|
||||||
`
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user