I have a PowerShell script that gets a list of files in a folder and all its subfolders, then reads them one by one checking for certain invalid values in each file. This script has run fine for many years on a Windows Server 2008 machine with 8gb of memory. Sorry, I don't remember the version of PS that was running then, but assume it was 3.0.
This server was recently upgraded to Windows Sever 2012 R2, added an addtional 8gb of memory and is running PSVersion 4.0. Ever since the upgrade, the script crashes the server by eating more and more memory until it is all exhausted. There are usually about 300,000+ files to examine each time the script is run, ranging in size from a few KB each up to around 300mb each. This is the warning error I see in Event Viewer after the crash and reboot:
Windows successfully diagnosed a low virtual memory condition. The following programs consumed the most virtual memory: powershell.exe (5964) consumed 66568437760 bytes, splunkd.exe (1900) consumed 263499776 bytes, and svchost.exe (1852) consumed 83922944 bytes.
What could be the difference between PS 3.0 and 4.0 that could cause this, or is it something with the OS?
As for these old OS versions, this is a legacy server that will be going away by the end of the year, but I have to keep nursing it and keep it alive until then. We only upgraded to 2012 as Win 2008 is considered a big security risk and the rest of the old software won't run on anything above Win 2012.
Thanks for any help with this issue.