Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 调用命令StackOverFlowException_Powershell_Powershell 2.0_Dynamics Ax 2012_Invoke Command - Fatal编程技术网

Powershell 调用命令StackOverFlowException

Powershell 调用命令StackOverFlowException,powershell,powershell-2.0,dynamics-ax-2012,invoke-command,Powershell,Powershell 2.0,Dynamics Ax 2012,Invoke Command,我正在尝试使用Invoke命令在远程计算机上运行脚本块 $scriptBlock = { Param( $remoteExportDir, $remoteMachine ) echo Y | .\DP.EXE IMPORT $remoteExportDir 'MicrosoftDynamicsAx' $remoteMachine } Invoke-Command -ComputerName $remoteMachine -Script

我正在尝试使用
Invoke命令
在远程计算机上运行脚本块

$scriptBlock = { 
    Param(
        $remoteExportDir,
        $remoteMachine
    )
    echo Y | .\DP.EXE IMPORT $remoteExportDir 'MicrosoftDynamicsAx' $remoteMachine 
}

Invoke-Command -ComputerName $remoteMachine -ScriptBlock $scriptBlock -AsJob -ArgumentList $remoteExportDir,$remoteMachine
脚本块是:

$scriptBlock = { echo Y | .\DP.EXE IMPORT $remoteExportDir 'MicrosoftDynamicsAx' $remoteMachine }
我按如下方式运行此脚本块:

Invoke-Command -ComputerName $remoteMachine -ScriptBlock $scriptBlock -AsJob
我运行这个,我可以看到它在远程机器上执行进程。此命令在本地运行大约需要40-50分钟。当我像这样远程操作时,它只运行大约25分钟

查看状态,它说它已完成,没有错误,但是
DP.exe
生成了一个日志文件,而它没有生成它。当我查看作业的输出时,我发现作业失败,并显示以下消息:

+ CategoryInfo : NotSpecified: (:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError Process is terminated due to StackOverflowException. Process is terminated due to StackOverflowException. +CategoryInfo:NotSpecified:(:String)[],RemoteException +FullyQualifiedErrorId:NativeCommandError 进程因StackOverflowException而终止。 进程因StackOverflowException而终止。
DP.EXE
是一个用于将数据导入Microsoft Dynamics AX 2012测试环境的应用程序。如果我只是在机器上本地运行这个命令,它就可以正常工作。我正在尝试编写一个脚本,以便按计划在一系列5台以上的计算机上运行此命令


我不确定为什么会出现这个StackOverFlowException,以及我能做些什么来解决它。

问题在于脚本块中的变量。当在远程机器上执行scriptblock时,该远程机器上的会话不知道这些变量是什么。为了解决这个问题,您需要将参数添加到scriptblock中,然后在远程计算机上调用它时将值传递给它

$scriptBlock = { 
    Param(
        $remoteExportDir,
        $remoteMachine
    )
    echo Y | .\DP.EXE IMPORT $remoteExportDir 'MicrosoftDynamicsAx' $remoteMachine 
}

Invoke-Command -ComputerName $remoteMachine -ScriptBlock $scriptBlock -AsJob -ArgumentList $remoteExportDir,$remoteMachine

问题是MaxMemoryPerShellMB配置为150mb的内存使用量。我增加了这个,它解决了这个问题。为此,我打开powershell并输入:


winrm set winrm/config/winrs'@{MaxMemoryPerShellMB=“2000”}'

DP.exe是内部编写的程序吗?不是,它来自Microsoft。我想知道这是否是远程会话的内存限制。我已将winrsrm/config/winrs MaxMemoryPershell设置为更高的限制。我看看这能不能解决问题。