r/PowerShell • u/Kodama_Keeper • Oct 22 '26
Question Environment stopped handling large files
Edit: To everyone who responded. You've given me some good ideas, and now I have to experiment to track down where the issue lies. Thanks to all.
I have a workflow which takes a comma delimited text file (*.txt) and updates an Azure database with the values. The workflow is called by a PowerShell script on a remote Windows Server, which looks to a folder and finds all the txt files in there, and runs the workflow against each one. This process worked fine for about two years. Then last spring, I started getting reports from our users that not all the values that should be updated in the database where. No one changed the workflow, and no one changed the PowerShell script.
After a lot of testing, we found that if the txt file was larger than 2K, only the first 2K worth of lines in the file were processed, and everything after was ignored.
On the suggestion of a consultant, he had me run the PowerShell script which calls the workflow from my own laptop. Yes, I had to duplicate the folder structure to make that happen. Much to my surprise, running the script and workflow from my laptop worked just fine.
So I started looking into what in the environment of the Windows Server would limit the ability to pass all the necessary data to the workflow. Of course our server teams swears they did nothing to the server, no updates that would cause this restriction. But I don't trust them to know what the consequences of their actions would be.
After half a year of cutting the text file down into 2K chunks every week (I automated the process, but still), I am again trying to find what the cause of this could be. Script works fine on my laptop, but choaks at 2K file size when run on a Windows Server. The server is more than powerful enough in terms of memory, processor and disk size.
If you have any clue, please pass it on.
4
u/BetrayedMilk Oct 22 '26
What is 2K? Like 2000 lines? 2KB? Why not add a counter (either incrementing on line number or whatever 2K is) to the script and add a breakpoint right before this threshold and debug it from the server? Or just add some logging temporarily.
3
u/creenis_blinkum Oct 24 '26
How could you not just run it from the server and… troubleshoot lol
2
u/CarrotBusiness2380 Oct 22 '26
I would guess it is a limit on how you are feeding the rows to the DB rather than something in the environment.
I know you said you tested locally before but I would test again. I have missed obvious things many times because I was in a rush or had a desire to not find a problem.
2
u/PinchesTheCrab Oct 23 '26
Need some code examples, because there's no particular reason why it should fail like that.
1
u/dodexahedron Oct 22 '26 edited Oct 22 '26
Can't you just use bcp?
If it is CSV-formatted, that's the proper way to be bulk loading data from files in the first place.
Also, if you mean 2K as in exactly consistently the same number of bytes be it 2000 or 2048, it sounds suspiciously like someone used a fixed-length char array somewhere like for a file io buffer of 4k and then, when output as utf8 text, the characters are half the size. I've seen that one before. And then that followed by using somwthing like File.WriteAllBytes from that buffer would just overwrite it.
Or the same concepts, but on the input side.
Or both.
Without seeing the input and output portion of the code, all we can do is speculate.
1
u/ka-splam Oct 23 '26
😂
Is it possible there were no files bigger than 2K before last spring?
1
u/Pvt-Snafu Oct 24 '26
A 2K cutoff smells like a buffer limit in how the file gets passed, not the file itself. Compare $PSVersionTable and the execution policy or remoting limits on the server versus your laptop.
1
u/xXFl1ppyXx Oct 24 '26
Are you using a stream or a Powershell cmdlet? Or even import CSV?
If not stream you definitely should try to do that. a csv is easy enough to split after the fact with one regex
1
u/RichDinero Oct 24 '26
I've done this for CSV files that have millions of rows. These CSV files will not even open because they are so large. By default, Excel will try to open. Once I forced it to open no new window it ran in the background for a while but ultimately was very successful with the file that you can't even open in notepad or Excel.
-5
u/DonJuanDoja Oct 22 '26
Google "powershell only processing txt file up to 2k size limit" it'll tell you stuff that might help.