Issues printing ZPL via powershell - powershell

Issue printing ZPL using powershell
I'm struggling to print a label based on ZPL commands via Powershell.
Im using this line to print the labels:
Get-Content ($folder + $labelname + '.txt')|Out-Printer -Name "Generic / Text Only"
When I run this an empty label comes out. I did some tests to narrow it down.
When I open the .txt file with notepad and print it manually, the label comes out fine
So it seems there aren't any issues with the syntax of the zpl commands.
The simple conclusion I made at that point, was that my powershell line isn't working.
To check this I used a simple zpl expample and stored it in a .txt file. When I used the same powershell line to print this label, it worked.
From this I concluded that there is something in the ZPL commands which causes problems for powershell. So I compared the ZPL commands and noticed that the non-working ZPL file uses ~DGR:TFORMer.GRF (see full content below) to generate an image.
Content of nonworkinglabel.txt:
^FXParcel_Std^FS
^MMT
^JMA
~DGR:TFORMer.GRF,121160,104,
zzzzzzzzzzzzzzzzzzzzlG03SFEg0jKF8jM0....FpM02zzzzzzzzzzzzzzzzzzznR0
^XA
^PW832
^LH0,0
^LS0
^LT0
^LL1165
^FO0,0
^XGTFORMer.GRF,1,1^FS
^XZ
^XA
^IDTFORMer.GRF^FS
^XZ
I left out some of the line underneath ~DGR:TFORMer.GRF,121160,104, because the page kept crasing
What do I have to change to my powershell script to make this work? Any help would be very welcome.

Related

Replace selectedText with Task output in Visual Studio Code

I have a task which passes highlighted text (${selectedText}) to an external script and the output gets printed in the terminal.
Is there anyway to have that script output replace the highlighted text?
:)
Even saving to a new file and merging into the existing file would be fine, that seems far more complicated though.
I found I can do this in a slightly more round about way than I intended. VSCode Tasks can be shell operations, so I solved the problem using bash shell tools like sed and awk.
1.) Have the output of my script get saved to a temporary file.
2.) Using sed -i I can strategically erase the highlighted lines (after determining the range of lines highlighted).
3.) Then using AWK I can paste the temp file output into specific lines in my primary file. I could do it all in sed or awk but found it easier to use both.
4.) Clean up by deleting the temp file.
So there is no all in one nice VSCode solution that I could find, but it is doable.

How to fix the utf8 issue for CSV read process

I have read and got the values from the CSV file. Sometimes I have faced the character encoding issue (uf8). Review my below sample code.
my $value = 'Storno lt. Gläubiger';
$value = encode( 'iso-8859-1', $value );
Result return as
Storno lt. Gl�ubiger
Storno lt. Gl\xE4ubiger
My expecting result is "Storno lt. Gläubiger"
How to fix the issue and get the expecting result.
Well, your question is not complete. You did not provide minimal code snippet to understand what you try to do.
You need to take in consideration your output device (probably a screen) which should support utf-8 output.
You did not provide any clue what OS (Operating System) you run the code in.
For example if you use Windows 10 (probably earlier version also will work) and try to get output into cmd terminal -- then before output you have to change code page to utf-8 which can be achieved with chcp 65001 command.
If you are in Windows then in cmd terminal window type help chcp and read some documentation.
If you write perl code and inside of the code you use utf-8 strings then you need add use utf8 in the beginning of your perl code.
Change default code page of Windows console to UTF-8

What happens when powershell script encounters EOF while a quote is open?

Unicorn.py generates a string that looks like
powershell -flag1 -flag2 "something " obfuscation; powershell "more gibbrish
Interestingly, if this command is saved in a file filename.txt Windows executes it before opening the file in notepad.txt (by which time the file is empty).
Why is the file executed despite the extension?
What does the script do when it encounters EOF after odd number of quotation marks?
Edited:
Unicorn (https://github.com/trustedsec/unicorn) is a script that "enables privilege elevation and arbitrary code execution". If you know what it means. Of course I did NOT put the actual string, just the key features.
Purely out of IT security interest.
I think that if you read the manual in unicorn.py, at absolutely no time does it say that the script should be left in the txt file.
The PowerShell script is written inside the txt file and called the "payload" (very hacker like). What is left for you is always how to execute this code on the victim's computer.
The manual proposes Word code injection, simply executing the PowerShell in cmd (I quote "Next simply copy the powershell command to something you have the ability for remote command execution."), Excel Auto_Open attack, and so on.
If reading the manual is too much there is always a video. The only time the "hacker" uses a notepad like is on his linux operated system (how ironic)… I watched it because I love this Papa Roach music Last Resort...
For those who are concerned about IT security I recommend this article dosfuscation. This is really instructive about how you have to be extra careful when receiving mails, outside document,... and how humanity can waste so much time spying, deceiving, inventing new twisted strategies... Aren't we great !
Windows like any other system has many system flaw but opening notepad is not one of them. Unless your notepad has been replaced by a hacker using unicorn…
There is an even number of brackets in the obfuscated script. Did you mix up '' with "?
Empty txt file means that you've sent the attack.txt over network to a drive accessible by updated antivirus and antivirus quarantined/deleted file contents. Since you didn't know about this interaction with antivirus your environment is NOT secure. Which means you might have other malware from previous test lurking on your "clean" network.

Remove Line Feeds and first character from large (2GB) XML file on Windows

I have an XML file from a third party and it is broken up into non-static length lines delimited with Line Feeds.
There is also a strange first character that needs to be stripped from the file.
I am fairly certain that the two items above are causing issues loading the XML file with SSIS. If I remove them by hand (from a smaller sample), the XML file loads fine thru SSIS.
At this point I've tried using both SSIS and Powershell to attempt to fix the file.
SSIS resulted in strangely adding delimiters back in.
My attempts using Powershell were a little more fruitful on a small subset of the data, but my actual file will regularly be in excess of 2GB and I keep getting System.OutOfMemory exceptions. I have increased the "maxmemorypershellmb" for Powershell (and restarted winrm) but it seems to have had no effect preventing the OutOfMemory error.
Current Powershell attempts that work with a small sample file:
-join ((Get-Content "C:\Code\input.xml") -replace '^\w$', '') | Set-Content -Path "C:\Code\output-nolinefeed.xml"
-join ((Get-Content "C:\Code\output-nolinefeed.xml").substring(1) | Set-Content -Path "C:\Code\output-nolinefeed-removefirstchar.xml"
If both of the above commands run on the sample file, it will then import into SSIS (XML Source -> Derived Column -> SQL Server Destination).
Looking at it in Notepad++ (below), see how it appears to have some type of black smudge on the "less than" character. The other "less than" characters all appear normal. Also, the neon green is some type of space I can select as well.
When I open the file, it is UTF-8. Choosing Encoding -> Covert to ASCII results in the space and "less than" character being converted to a single question mark.
Reasons for weird first character and line feeds aside (assuming both cannot be handled with SSIS), at this point I need some command line editor that will gracefully handle large files.
I would use the Foxe editor for monster XML files:
http://www.firstobject.com/dn_editor.htm
It is astoundingly quick and seems reliable as far as I've used it.
Apparently it has a scripting language based on C++, but I havent tried that.

PowerShell scripts on GitHub

PowerShell $OutputEncoding defaults to ASCII. PowerShell by default represents strings in Unicode. When I create scripts using the ISE, they are created in Unicode.
The following command sends text to a file in Unicode:
echo Testing > test.txt
When I push these files to GitHub, the code view chokes on them because they aren't UTF-8.
I'm confused about the best solution, with the least amount of work during commit.
I know I could convert each file and then commit, but that seems cockeyed to me. Clearly, I can't change how PowerShell represents strings internally, nor would I want to.
What are others doing?
ISE preserves an existing file's encoding but when you create a new file with ISE it is always creates the file with Unicode encoding. This has nothing to do with the $OutputEncoding. IIRC it was deemed a bug late in the dev cycle - too late to fix. Anyway, you can work-around this by going to the command window the first time you save a file and execute:
$psISE.CurrentFile.Save([Text.Encoding]::ASCII)
After that, you can just press the Save button.