Out-printer command causes endless page counting loop with Zebra GK420d printer - powershell

I'm trying to write a PowerShell script to send data directly to Zebra GK420d label printer. "Out-Printer" produces endless count of pages and data not being sent to the printer.
Commands:
"data" | Out-Printer "ZDesigner GK420d"
or
Get-Content C:\barcode.txt | Out-Printer "ZDesigner GK420d"
result in producing print job with endless page counting and nothing being printed.
What worked for me was to share Zebra in my network and setting it up as lpt1 port:
net use lpt1: \\host\Zebra
I was able to copy a *.txt file with ZPL contents and it was interpreted correctly by the printer:
copy barcode.txt lpt1
That would work well as a work-around solution, but I'm trying to run this script on a server without admin rights. So sharing a printer or setting lpt1 cannot be done.
I want to be able to send data directly to the printer using PowerShell script, just like it can be done with "Print preferences>Tools>Action>Send command" or in Zebra Setup Utilities > Open Communication With Printer.
Any suggestions will be appreciated.

Inside of the Link-OS SDK there is a .NET SDK. This contains an command line exe which could be used from your script.
http://techdocs.zebra.com/link-os/2-14/pc_net/
Go to the link for "Use the command line"

I added new printer with "Generic \ Text driver" and pointed it to the USB002 port with Zebra printer. I can now use Out-Printer command as intended. Thanks for the answers.

Related

How can I execute this line of code in the run box?

I have the following line of code that I use to download and combine dns text records from my website and execute them in powershell. I can run this command just fine from the console but can not figure out how to effectively run it from the run box (win+r)
1..3|%{$p+=Resolve-DnsName "$_.website.com." -Ty TXT -EA 0|% S*s};& ([scriptblock]::Create($p))
Below is a simplified version I use to pull down and execute a single dns text record using a single word instead of iterating through through numbers and combining them.
powershell . (nslookup -q=txt example.website.com)[-1]
The above simplified version works fine from the console but in order for it to work in the run box it has to be modified as seen below:
powershell "powershell . (nslookup -q=txt sub.website.com)[-1]"
I can not seem to find a way to modify that first example in a way that allows me to execute it from the run box. Doing something like the example below errors out. I have tried about 20 variations of the code below with no success
powershell .(1..3|%{$p+=Resolve-DnsName "$_.website.com." -Ty TXT -EA 0|% S*s};& ([scriptblock]::Create($p)))
Try the following:
powershell 1..3|%{$p+=Resolve-DnsName \"$_.website.com.\" -Ty TXT -EA 0|% S*s};& ([scriptblock]::Create($p)))
The crucial change is to escape the " chars. as \", so that PowerShell considers them part of the command to execute.
See this answer for more information.
There's no reason to use . (...) for execution - just use ... directly, as shown.
Note that the above command only works from no-shell environments such as the Windows Run dialog (WinKey-R) - to execute it from cmd.exe, you'd need additional quoting or escaping.

Cannot redirect EXE output to file

I have an exe program I'm running on Windows 10 using PowerShell. When I run it, I get the following output.
> .\Program.exe
Unlocked level 7/10
When trying to redirect all output or just stdout to a file, the program stops giving output. For example
PS > .\Program.exe > .\out.txt
PS > cat .\out.txt
PS >
I did not write the program but what I know is that it was written in C++.
Is there any trick to get the output into a file? I tried running in python and writing output to a file, running in python without fetching the output and redirecting, running from another powershell, and lots of other combinations but they don't seem to be working. Also, when running from Git Bash, I get no output at all.
I was thinking about some checks on the descriptors but I'm not sure since I don't have the source code, only the asm code
It looks like Program.exe is actually generating an error, and not output, first commenter is trying to get you to see that, but not really explaining that part...
(NOTE: You aren't actually using any powershell besides an implied "Invoke-Expression")I think you might be dealing with STDERR vs. STDOUT, when I invoke reg.exe in that fashion from powershell I get no output to the text file. This is because the text I was seeing was an error message ( Contents of STDERR ) from reg.exe, not the output ( contents of STDOUT ) from the command. When I passed proper parameters to it ( reg query HKLM\Software\Microsoft > C:\Users\foo\Documents\foo.txt) it wrote the Contents of STDOUT to the text file instead of the screen.
Here is an article that explains it better than I just did:
https://support.microsoft.com/en-us/help/110930/redirecting-error-messages-from-command-prompt-stderr-stdout

Printing ESC/POS (raw) using windows powershell

I am trying to print receipts on my Epson TM20ii using ESC/POS commands, sending them to the printer with out-printer' I have tried using both the epson driver and a generic text driver. My problem is that the printer is printing the command instead of executing it. See example
"LF" | out-printer -name epson
LF is the command for the printer to feed one line, instead of doing so the printer is printing the characters LF
I figured it out.
as some users commented, the commands are referring to the actual ASCII characters.
this however did not fully solve the problem as for some reason the powershell out-print command was sending the info to the printer in a way that the printer did not understand to be meant to be interpreted as esc-pos commands. The easiest solution that i found so far is a command line utility called RawPrint.exe which can be found here. The tool is very straight forward and i highly recommend it.

How to print (to paper) a nicely formatted page with Powershell?

I need to print a nicely formatted (bold and 3 different fonts) page to a remote printer queue with Powershell. Unfortunately I did not find a usable solution for printing. Searching Google, most answers are: create a .html file and print this file with Internet Explorer. My Powershell script runs from an Windows service (a backup software). It seams that Internet Explorer can't be launched from an service, so I cant print the .html file. Powershell is the only scripting language available in this context. Now I search for an solution to print an .html or .xps file from Powershell?
Thanks in advance.
Suggestions:
Have your service...
1 - Try creating a normal scheduled task that looks to a folder where you output the HTML file, and print via a normal PoSH script via the scheduled task.
2 - Create / Register a WMI event that that monitors a folder where you plan to output the html and print similarly via a normal PoSH script

PowerShell: send console output to file without deafening this console output

I have a lot of PowerShell script. One main, that calls other, child ones. Those PS scripts in their turn call windows CMD scripts, bash scripts and console applications. All these scripts and applications write messages to console. PowerShell scripts, for example, are using Write-Host scriptlet for this purpose.
Question: how can I easely redirect (send) all this console output to some file, while not deafening (canceling) this console output? I want to be able to see whats going on from console output and also have history of messages in log file.
Thanks.
You can use the tee equivalent of PowerShell : Tee-Object
PS: serverfault.com and/or superuser.com are more suitable for a question like this.
You can try Start-Transcript and Stop-Transcript. It has a couple of limitations like not capturing native exe output. It is also global to PowerShell session.
I've found script for grabbing console output: http://gallery.technet.microsoft.com/scriptcenter/e8fbffde-7d95-42d9-81de-5eb3d9c089e0. Script returns HTML to preserve colors.
The only big downside - you must call it at the end of your script to capture all console output it have made.
You'd probably need to write a custom host to do this. It's not a terribly hard thing to do, but it's does require some managed code.