<# .SYNOPSIS Sends a .zpl file to a Zebra printer, the only way a printer takes one. .DESCRIPTION A .zpl file is the bytes the printer wants, not a document. Opening it in Notepad and pressing print sends it through a Windows driver, which adds its own formatting and prints the ZPL as words - the classic way to get a label covered in ^FO and ^FS. It has to go to the raw port, 9100, exactly as it sits on disk. That is all this does. It is the partner to the Parts page's "Download .zpl" button. The Print button beside it needs Zebra Browser Print installed and the browser's permission to reach the local network; this needs nothing at all, works in any situation, and is the fallback worth knowing. Written 11-11-2026, after a day proving the label itself was never the problem. .PARAMETER File The .zpl file. Drag one onto send-zpl.cmd and this is filled in for you. .PARAMETER Address The printer's IP. Defaults to $env:ZPL_PRINTER so it can be set once: setx ZPL_PRINTER 192.168.1.81 .PARAMETER Port The raw port, 9100 unless the printer says otherwise. **Not 9101** - that is a second port on a multi-port print server and is refused on a ZM400. .EXAMPLE .\send-zpl.ps1 "$env:USERPROFILE\Downloads\DRY-1004.zpl" 192.168.1.81 .EXAMPLE setx ZPL_PRINTER 192.168.1.81 .\send-zpl.ps1 .\DRY-1004.zpl #> param( [Parameter(Mandatory = $true, Position = 0)][string]$File, [Parameter(Position = 1)][string]$Address = $env:ZPL_PRINTER, [int]$Port = 9100 ) $ErrorActionPreference = 'Stop' if (-not (Test-Path -LiteralPath $File)) { Write-Host "There is no file at $File" -ForegroundColor Red exit 1 } if ([string]::IsNullOrWhiteSpace($Address)) { Write-Host "No printer address. Pass one, or set it once:" -ForegroundColor Red Write-Host " setx ZPL_PRINTER 192.168.1.81" exit 1 } # Read as BYTES, never as text. Reading it as a string and writing it back # would re-encode it, and a BOM or a changed line ending in front of ^XA is # the difference between a label and a sheet of nothing. $bytes = [System.IO.File]::ReadAllBytes((Resolve-Path -LiteralPath $File).Path) # **Said, not refused.** A file with no ^XA is almost certainly not a label, # but a printer will take configuration and control commands too (~HS, ^JUS), # and refusing those would make this useless for the thing it is best at. $head = [System.Text.Encoding]::ASCII.GetString($bytes, 0, [Math]::Min(400, $bytes.Length)) if ($head -notmatch '\^XA') { Write-Host "Note: no ^XA in the first 400 bytes - if this is not a label, it is being sent anyway." -ForegroundColor Yellow } $client = New-Object System.Net.Sockets.TcpClient try { # A printer that is off answers nothing at all, so the wait is capped - # the default would sit there for twenty seconds saying nothing. $connect = $client.BeginConnect($Address, $Port, $null, $null) if (-not $connect.AsyncWaitHandle.WaitOne(5000, $false)) { throw "no answer from ${Address}:${Port} in 5 seconds - is it on, and on this network?" } $client.EndConnect($connect) $stream = $client.GetStream() $stream.Write($bytes, 0, $bytes.Length) $stream.Flush() Write-Host "Sent $($bytes.Length) bytes of $(Split-Path -Leaf $File) to ${Address}:${Port}" -ForegroundColor Green Write-Host "The printer is the only place that knows whether it printed - go and look." -ForegroundColor DarkGray } catch { Write-Host "Could not send it: $($_.Exception.Message)" -ForegroundColor Red exit 1 } finally { if ($client.Connected) { $client.Close() } $client.Dispose() }