Applications Systems

PowerShell components return 'System.OutOfMemory' exception'

This article explains issues regarding Windows PowerShell components that return a System.OutOfMemory exception, and includes ways to resolve those issues. Please note that SolarWinds does not configure, write, or support custom PowerShell scripts. Windows PowerShell Monitors may intermittently return Out of Memory exceptions.

First published date

11/15/2018 2:02 AM

Last published date

6/15/2020 10:23 PM

Overview

This article explains issues regarding Windows PowerShell components that return a System.OutOfMemory exception on clients, and includes ways to resolve those issues. Please note that SolarWinds does not configure/write/support custom PowerShell scripts.

Product section

Server Application Monitor

Cause

Processes that run PowerShell scripts have a set memory limitation — the default is 150 MB. If a few scripts return very large results, or a large amount of scripts run simultaneously and consume memory past the limit, System.OutOfMemory exceptions may occur on client machines.

The larger the script, the more CPU and memory resources are required to run it, which can exceed the abilities of the machine running the polling job.

Resolution

To check how much memory is allocated to the PowerShell process, run this command from the elevated PowerShell prompt on the client machine:
 

<#

Scripts are not supported under any SolarWinds support program or service. Scripts are provided AS IS without warranty of any kind. SolarWinds further disclaims all warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The risk arising out of the use or performance of the scripts and documentation stays with you. In no event shall SolarWinds or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the scripts or documentation.

#>

get-item wsman:localhost\Shell\MaxMemoryPerShellMB

 

To increase the amount of allocated memory to resolve issues related to running a few scripts that return a large amount of results, run this command from an elevated PowerShell prompt on the client machine:
 

<#

Scripts are not supported under any SolarWinds support program or service. Scripts are provided AS IS without warranty of any kind. SolarWinds further disclaims all warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The risk arising out of the use or performance of the scripts and documentation stays with you. In no event shall SolarWinds or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the scripts or documentation.

#>

set-item wsman:localhost\Shell\MaxMemoryPerShellMB AmountInMB

 

If running a large number of PowerShell scripts and System.OutOfMemory errors occur, add a garbage collection line to scripts that run at a regular interval to release the process memory. This can help prevent scripts from consuming memory past the maximum limit by freeing memory at the end of script execution. To learn more about garbage collection, click here. (© 2017 Microsoft, available at https://www.microsoft.com/, obtained on November 21, 2018).

Consider hosting the polling engine on a 64-bit system. 64-bit machines have better capabilities in terms of memory management so they can process larger files (for example, over 1 GB) than 32-bit machines. 

Disclaimer: Please note, any content posted herein is provided as a suggestion or recommendation to you for your internal use. This is not part of the SolarWinds software or documentation that you purchased from SolarWinds, and the information set forth herein may come from third parties. Your organization should internally review and assess to what extent, if any, such custom scripts or recommendations will be incorporated into your environment.  You elect to use third party content at your own risk, and you will be solely responsible for the incorporation of the same, if any.