Hello, mark.chuman-
I have encountered this before. There are several things that you can do in your scripts to allow memory to be released back to the system. One thing that is probably directly relevant to the script you were running when you received that error (since the error is on call to Get-View):
use the "-Property" parameter for Get-View so as to retrieve only the properties that you will be using later in the script
This will not only greatly reduce the amount of memory consumed, it will substantially increase the speed of the call, as Get-View will only be retrieving the given properties from the .Net View objects, instead of all of the properties (default).
Example: say you wanted to get host memory info, you could use the following to just retrieve the pertinent info:
Get-View -ViewType HostSystem -Property Name,Hardware.MemorySize | `
Select Name,@{n="Mem(GB)"; e={[Math]::round($_.Hardware.MemorySize / 1GB, 0)}}
That way, rather than taking the extra time and consuming the extra memory to retrieve all of the properties of the HostSystem View object, you get just the ones that you intend to utilize later in the script.
Another way to save memory is to utilize the pipeline, rather than storing results in an array/hashtable. It can take a bit of re-writing, and some extra planning for the script, but it is well worth it to not run out of memory in PowerShell when the script is 75 minutes in...
If you feel like sharing that script, I'm sure that we could optimize it such that it will cause no more memory issues.