I'm trying to use Invoke-Command
to run a scriptblock on a remote machine.
The scriptblock is:
$scriptBlock = { echo Y | .\DP.EXE IMPORT $remoteExportDir 'MicrosoftDynamicsAx' $remoteMachine }
I run this scriptblock like this:
Invoke-Command -ComputerName $remoteMachine -ScriptBlock $scriptBlock -AsJob
I run this and I can see it executing the process on the remote machine. This command takes about 40-50 minutes to run locally. It only runs for about 25 minutes when I do it remotely like this.
Looking at the status it says it completed with no errors but the DP.exe
generates a log file and it's not generating it. When I look at the output of the job I see that it failed with this message:
+ CategoryInfo : NotSpecified: (:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError Process is terminated due to StackOverflowException. Process is terminated due to StackOverflowException.
DP.EXE
is an application to import data into a test environment for Microsoft Dynamics AX 2012. This command works without issue if I just run it locally on the machine. I am attempting to write a script to run this command across a series of 5+ machines on a schedule.
I'm not sure why I'm getting this StackOverFlowException and what I can do to get by it.
The issue was MaxMemoryPerShellMB was configured for 150mb of memory usage. I increased this and it solved the problem. To do this I opened powershell and put in:
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="2000"}'