I had a very similar situation to the following post: Another StackOverflow Post
However, after running the PS script, inputting the data, and letting it roll, I get a window that pops up saying "Printing page # of document" where '#' begins counting - I've let it hit 70+ before I cancel the print request, as I do not want to waste labels.
Here is my code:
$AllPrinters = gwmi win32_printer -computername $env:computername
$DefaultPrinterString = $AllPrinters | where {$_.Default -eq $true}
$DefaultPrinter = [regex]::match($DefaultPrinterString, '\"([^\"]+)\"').Groups[1].Value
$targetPrinter = "PDC CERTIS B2-20"
$fn = Read-Host -Prompt "Enter patient first name: "
$ln = Read-Host -Prompt "Enter patient last name: "
$dob = Read-Host -Prompt "Enter patient DOB (use mm/dd/yyyy as format): "
$mrn = Read-Host -Prompt "Enter patient record number: "
$pt = New-Object PSObject -Property @{
MedRecNum = $mrn
FirstName = $fn
LastName = $ln
DOB = $dob
}
$print_code = "^XA
^FO100,200^ADR,48,30^FDLast Name: " + ($pt.LastName) + "^FS
^FO20,200^ADR,48,30^FDFirst Name: " + ($pt.FirstName) + "^FS
^FO100,900^ADR,48,30^FDDOB: " + ($pt.DOB) + "^FS
^FO50,1600^BY3^B3R,N,100,Y,N^FD" + ($pt.MedRecNum) + "^FS
^PQ1^MCY
^XZ"
$print_code | Out-File -FilePath C:\temp\ezWrist.zpl #This was to check if the print code above wrote to file
#I've also tried using Get-Content -Path and piping it to Out-Printer as the whole file --- no such luck
(New-Object -ComObject WScript.Network).SetDefaultPrinter($targetPrinter)
$print_code | Out-Printer
Start-Sleep 1
(New-Object -ComObject WScript.Network).SetDefaultPrinter($DefaultPrinter)</code>