Console icon indicating copy to clipboard operation
Console copied to clipboard

Powershell Script running is showing error

Open iprateeksunny opened this issue 2 years ago • 7 comments

Expected Behavior When we run Powershell script in Powershell ISE in Sitecore. Then it should generate the desired output/result.

Actual Behavior In Sitecore 9.2 environment, when we are running Powershell script on PowerShell console. After some time, we are seeing one exception and script execution is failing.

Steps to Reproduce the Problem We copy the script and open Powershell ISE and execute the script then after some time we see below error:

Exception of type: 'System.OutOfMemoryException' was thrown, at Line: 60 Char: 21

And it is happening with every script.

image

Sitecore Version: 9.2 Powershell Version: 5.1

iprateeksunny avatar May 06 '23 09:05 iprateeksunny

The line throwing the exception doesn't appear in your screenshot. My guess is that the query is quite broad and the machine (local?) runs out of memory. What is the value of your scope query and how many items does that match?

michaellwest avatar May 08 '23 13:05 michaellwest

Please let me know if any other information is required to investigate the issue

iprateeksunny avatar May 19 '23 08:05 iprateeksunny

Get-Contacts and Get-Value appear to be custom functions. What do they do?

michaellwest avatar May 25 '23 17:05 michaellwest

Can you provide a more complete example of your script? The screenshots do not provide much context into what is happening in the script.

michaellwest avatar May 25 '23 17:05 michaellwest

Apologies. the script is different. We are getting this error:

image

and the line(69) throwing the exception are as below:

image

This issue is occurring only on production. If we run the same script on any lower environments then it works as expected. Please let me know if anything else is required to investigate the issue.

iprateeksunny avatar May 26 '23 07:05 iprateeksunny

Please let me know if there is anything else required to investigate the issue.

iprateeksunny avatar May 30 '23 14:05 iprateeksunny

One idea I had over the weekend was to remove the call to Initialize-Item (and everything after) to see if the call to Find-Item completes. See if you can get a count of the items returned. My guess would be that the scope query is far too broad and you eating up your server memory. There are ways to paginate with Find-Item.

michaellwest avatar May 30 '23 15:05 michaellwest

There are no clear reproduction steps that would allow us to fix this issue. Please provide script that will cause the issue on a clear Sitecore instance, otherwise we have to assume it's 3rd party code that is causing it.

AdamNaj avatar May 09 '24 21:05 AdamNaj