PowerShell job failing after upgrading agent - System.OutOfMemoryException
search cancel

PowerShell job failing after upgrading agent - System.OutOfMemoryException

book

Article ID: 253959

calendar_today

Updated On:

Products

CA Automic Workload Automation - Automation Engine CA Automic One Automation

Issue/Introduction

Running a PowerShell script via Automic Automation agent throws the following error

:\>powershell.exe -ExecutionPolicy Bypass -Command "H:\MSSQL2016\MSSQL`$DEFAULT\RDM_Automation\Scripts\FinancialAccount_FormatFile_SAPECC.ps1" Get-Content : Exception of type 'System.OutOfMemoryException' was thrown.At H:\MSSQL2016\MSSQL$DEFAULT\RDM_Automation\Scripts\FinancialAccount_FormatFile_SAPECC.ps1:7 char:17+ $fileContents = Get-Content -path $filepath+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : NotSpecified: (:) [Get-Content], OutOfMemoryException    + FullyQualifiedErrorId : System.OutOfMemoryException,Microsoft.PowerShell.Commands.GetContentCommand 

 

This had been previously working as expected.

Environment

Release : 12.3.x, 21.0.x

Cause

This happens when trying to read a file larger than the default memory settings for PowerShell.
The default memory is 150MB.

Resolution

To find the current PowerShell memory setting, run the following command in an elevated (Run As Administrator) PowerShell command prompt:

Get-Item WSMan:\localhost\Plugin\Microsoft.PowerShell\Quotas\MaxMemoryPerShellMB

To change the value to 4G, for example, you would run

Set-Item WSMan:\localhost\Plugin\Microsoft.PowerShell\Quotas\MaxMemoryPerShellMB 4096

Then restart WSMan using

Restart-Service winrm 

Additional Information

If the following error is returned when running the Get-Item command:

Start WinRM Service
WinRM service is not started currently. Running this command will start the WinRM service.

Do you want to continue?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): 
The client cannot connect to the destination specified in the request.

Just run:

Restart-Service winrm 

and then run the Get-Item command again.

Attachments