Category filter

How to Print Text to a Printer via Windows Scripts?

For organizations managing physical records—such as contracts, shipping labels, or patient records—manual printing is an operational bottleneck. Hexnode UEM allows administrators to automate text-based printing across a dispersed Windows fleet, transforming a local task into a centralized administrative workflow.

By utilizing the Execute Custom Scripts feature within the Hexnode UEM console, administrators can deploy commands that leverage the local Windows operating system and printer drivers to directly send text and files to connected printers, ensuring immediate and accurate document printing from a centralized control point.

Implementation Scenarios

Deploying PowerShell and Batch scripts via Hexnode UEM provides a reliable bridge between digital administration and physical record-keeping, supporting a variety of practical requirements.

  • Logistics and Fulfillment: Automate the generation of packing slips or shipping manifests at specific warehouse terminals, ensuring paperwork is ready the moment a shipment is processed.
  • Retail Operations: Dispatch end-of-day transaction logs or internal invoices to back-office printers, removing the need for staff to manually interact with the local Windows OS.
  • Audit and Compliance: Generate time-stamped hardware status reports or system health checks using the %date% and %computername% variables, creating a physical paper trail for security audits.
  • Healthcare Administration: Send patient check-in notifications or departmental alerts to nursing stations by targeting specific printer names within the clinical environment.
  • Unattended Kiosks: Remotely trigger the printing of visitor badges on devices where no physical keyboard or mouse is accessible to a user.

Technical Requirements

To ensure the successful deployment of these automated print scripts, the target Windows endpoints must meet the following technical requirements.

Category Requirement
Operating System Windows 10/11 (Pro, Enterprise, or Education).
Management Hexnode UEM Agent must be installed and initialized.
PowerShell Version 5.1 or higher (standard on modern Windows).
Printer Setup The target printer must be pre-installed on the local machine.
Service Status The Windows Print Spooler service must be running.
Naming The $printerName in the script must match the “Friendly Name” in Windows Settings exactly.
Notes:

  • Scripts will not work with “Microsoft Print to PDF” or other virtual drivers as they require manual file-naming dialogs, which are blocked in a non-interactive UEM context.
  • The sample scripts provided are adapted from open-source repositories and are intended for foundational use. Administrators must review and execute them on a test machine before initiating a bulk deployment across the production environment.

PowerShell Script to send custom text to a printer

This script is the most reliable method. It defines the custom text and targets a specific printer name. If the printer is offline, the Windows Spooler will hold the job until the device reconnects.

To execute this script via Hexnode UEM, follow the given steps:

  1. Navigate to the Manage tab in your Hexnode UEM console and select your Windows device.
  2. From Actions, select Execute Custom Script from Deployments.
  3. Upload the .ps1 PowerShell script and click Execute.

Screenshot of the Action History page showing the output after executing the PowerShell Script to print text to printer

Batch Scripts to send custom text to a printer

This script uses a Batch wrapper to pipe dynamic text into a background PowerShell command. It is useful for environments where Batch is the preferred scripting standard.

Screenshot of the Action History page showing the output after executing the Batch Script to print text to printer

Post-Execution Verification of the Script

The text payload is dispatched straight to the printer spooler for immediate output if the device is online. If the printer is currently disconnected, the job is cached in the Windows print queue and will resume automatically once the connection is re-established.

To audit the execution status and verify script success within the Hexnode UEM console, follow these steps:

  1. Locate the Device: Navigate to the Manage tab and select the specific Windows endpoint.
  2. Access Logs: Within the device details page, click on the Action History tab to view all remote operations.
  3. Validate Output: Find the Execute Custom Script entry. If the status is “Success,” click the Show Output button to review the confirmation messages.

Troubleshooting common errors

Issue Potential Cause Recommended Solution
Error: Printer not found The $printerName variable does not match the printer “Friendly Name” in Windows exactly. Run Get-Printer command in the terminal to obtain a list of installed printers in the device to identify the exact friendly name
Script hangs / Timing out The printer is a “Print to PDF” or virtual driver requiring a save location. Ensure that a physical printer is targeted. Virtual printers require a UI interaction that is blocked in the UEM context.
Script hangs / Timing out The printer is a “Print to PDF” or virtual driver requiring a save location. Ensure that a physical printer is targeted. Virtual printers require a UI interaction that is blocked in the UEM context.
Success reported, but no printout The Print Spooler service is stuck or the printer is offline. Restart the spooler using Restart-Service Spooler command in terminal. Check the physical printer for paper jams or “Offline” status.
Garbage characters printed The printer driver does not support plain text streaming. Ensure the printer is using a standard Windows-compatible driver (PCL or PostScript) from the Printer Properties from Windows Settings > Bluetooth & devices (or Devices) > Printers and scanners > Target printer > Printer Properties > Advanced.
Sample Script Repository