- CMD y PowerShell allow you to print files and manage print queues.
- The PRINT command and Out-Printer are key methods in Windows.
- It is possible to print images and documents using automated scripts.
- PowerShell offers advanced options such as print server management.
Printing from the command line is a useful option when you want to automate processes or work in environments without a graphical interface. Both CMD and PowerShell in Windows offer specific tools and commands for sending documents to the printer and managing print jobs without needing to open additional applications.
In this article, we'll explore different ways to print from CMD and PowerShell, analyzing commands like PRINT in CMD and Out-Printer in PowerShell. We'll also explain how to manage network printers and how to deploy a print server using PowerShell.
How to print from CMD in Windows
CMD offers a built-in command called PRINT for sending text files to the printer. It's a simple and quick solution for printing basic documents without needing to open any additional programs.
Using the PRINT command
The PRINT command allows you to send a text file to a specific printer or the default printer. Its basic syntax is:
PRINT [/D:dispositivo] [unidad:][ruta]archivo
- /D:device: Specifies the destination printer.
- [drive:][path]file: Indicates the file you want to print.
For example, to print a document called document.txt on the default printer:
PRINT C:\documento.txt
If you wish to print to a specific network-connected printer with the IP address 192.168.1.100 , you can use:
PRINT /D:\\192.168.1.100 C:\documento.txt
Printing using the LPR command
In advanced versions of Windows, the LPR command can also be used to print files to network printers:
lpr -S 192.168.1.100 -P nombre_impresora archivo.txt
Here, -S indicates the IP address of the print server and -P the name of the printer configured on the network.
How to print from PowerShell
PowerShell offers more control over printing than CMD. It allows you to print files, manage print queues, and manage print servers.
Printing with the Out-Printer cmdlet
The Out-Printer cmdlet sends the output of a command or file to a printer. Its basic syntax is:
Get-Content C:\documento.txt | Out-Printer
If you want to use a specific printer on the network:
Get-Content C:\documento.txt | Out-Printer -Name "\\Servidor01\Impresora"
Print images from PowerShell
To print images from PowerShell, you can use Microsoft Paint with the following command:
mspaint /pt C:\imagen.png
If you want to print to a specific printer:
mspaint /pt C:\imagen.png "Nombre de impresora"
Advanced printer management with PowerShell
PowerShell also allows for advanced printer management, from installing drivers to configuring print servers.
Install the Print Server Role
To install the print role on a Windows server:
Install-WindowsFeature -Name Print-Server
After installation, it is recommended to restart the server:
Restart-Computer
Add a printer to a server
To add a printer to a server, a series of steps must be followed:
- Check the installed drivers:
Get-PrinterDriver - Add the driver if not available:
Add-PrinterDriver -Name "HP Universal Printing PCL 6" - Configure a printer port:
Add-PrinterPort -Name "10.1.1.123" -PrinterHostAddress "10.1.1.123" - Create the shared print queue:
Add-Printer -Name "HP Universal" -DriverName "HP Universal Printing PCL 6" -Shared -ShareName "HP Universal" -PortName "10.1.1.123" -Published
These steps allow for the complete configuration of a printer on a Windows server so that it is available on the network.
For more information on how to clear the print queue, you can refer to this article on managing the print queue in Windows 10.
Delete a printer
If you need to remove an installed printer, you can do so by:
Remove-Printer -Name "HP Universal"
Printing Automation in PowerShell
PowerShell allows you to automate certain printing processes through scripting. A simple example of scheduled file printing would be:
$archivos = Get-ChildItem C:\Documentos\*.txt foreach ($archivo in $archivos) { Get-Content $archivo.FullName | Out-Printer }
This will print all text files in the specified folder.
The ability to print directly from CMD or PowerShell offers an efficient alternative for document management on Windows systems. While CMD is suitable for simple tasks, PowerShell provides greater control and flexibility, allowing you to manage printers, print servers, and even implement automated tasks. By understanding these methods, any user or IT administrator can optimize printing processes in their work environment.
If you're interested in learning more about other advanced internet features that can complement your use of PowerShell, you can check out this article on advanced internet options.
Passionate writer about the world of bytes and technology in general. I love sharing my knowledge through writing, and that's what I'll do on this blog, show you all the most interesting things about gadgets, software, hardware, tech trends, and more. My goal is to help you navigate the digital world in a simple and entertaining way.
