r/PowerShell • u/fakir_the_stoic • Nov 21 '25
How to increase max memory usages by power shell
I have a PowerShell script and that is creating a JSON file. That is giving system out of memory error after utilising approx 15GB memory. My machine is having 512 GB ram. Is there a way to override this default behaviour or someone can help with a workaround. I did ChatGPT but no LUCK.
18
Upvotes
1
u/fakir_the_stoic Nov 25 '25
I able to get it working. Getting data in chunks and then appending it in a json file. Strange thing is that the file created this way is having approx 30-40% less size. Doing data validation if not loosing any data.
4
u/jkaczor Nov 21 '25
If you are looping, are you manually releasing memory using the .NET garbage collection calls? Just a week ago, I was able to get some scripts that were gobbling 1.6gb of RAM down to never using more than 200mb during processing by sprinkling calls to a wrapper function at the tail end of my loops/looped-functions:
3
u/jeffrey_f Nov 21 '25
Chunk read a large file otherwise the default action is to consume the whole file and work in memory.
1
u/Morph707 Nov 21 '25
Do it in chucks so you do not use all the ram.
-4
u/cherrycola1234 Nov 21 '25 edited Nov 21 '25
This sounds like you are not on a server grade OS. Normal windows OS home, Pro, & enterprise cap memory utilization at 15GB. On windows server grade OS there is no maximum you can set it to other than the max per server has installed.
You can "try" to get around this hard cap with the following. Make sure you change the 15360 to whatever you want to set memory to "in MB remember 1024 MB is 1 GB"
Navigate to the Shell directory
cd WSMan:\localhost\Shell
Set the maximum memory per shell to 15360 MB (15 GB)
Set-Item .\MaxMemoryPerShellMB 15360
Restart the WinRM service
Restart-Service WinRM
If it still stops at 15 GB than you will need to divert to a server grade OS.
0
u/[deleted] Nov 21 '25
[deleted] — view deleted comment
0
u/[deleted] Nov 21 '25
[deleted] — view deleted comment