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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.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 2.0 invoke命令在脚本中中断,但在断点处工作_Powershell_Powershell 2.0 - Fatal编程技术网

Powershell 2.0 invoke命令在脚本中中断,但在断点处工作

Powershell 2.0 invoke命令在脚本中中断,但在断点处工作,powershell,powershell-2.0,Powershell,Powershell 2.0,我正在编写powershell脚本,其中一部分需要检查另一个系统上故障转移群集的状态。为此,我运行了这行代码(通常是一行,但为了便于阅读,我将其拆分为多行): 然后我检查结果。运行脚本不正常,所以我在它后面放了一个断点。奇怪的是。在断点处,$result为null。但是,如果在脚本挂起时,使用相同的变量将精确的行剪切并粘贴到shell中,它将返回正确的结果 我试图用一个更简单的脚本重新创建它,我可以在这里发布,但是在一个带有本地定义变量的小脚本中运行相同的命令(见下文),它运行得很好。我能想到的

我正在编写powershell脚本,其中一部分需要检查另一个系统上故障转移群集的状态。为此,我运行了这行代码(通常是一行,但为了便于阅读,我将其拆分为多行):

然后我检查结果。运行脚本不正常,所以我在它后面放了一个断点。奇怪的是。在断点处,$result为null。但是,如果在脚本挂起时,使用相同的变量将精确的行剪切并粘贴到shell中,它将返回正确的结果

我试图用一个更简单的脚本重新创建它,我可以在这里发布,但是在一个带有本地定义变量的小脚本中运行相同的命令(见下文),它运行得很好。我能想到的唯一可能的作用域差异是,在损坏的版本中,它作为我编写的对象scriptmethod的一部分运行。但是,所有变量都可以在运行之后从挂起的断点获得

有没有人想过我该怎么做

工作版本(同样,最后一行格式化为可读性):

仅供参考,从系统获取主机:

Name             : ConsoleHost
Version          : 2.0
InstanceId       : 65fcc12c-4333-49d8-a340-92690d7aeb23
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace
编辑(美国东部时间7月25日11:00)--英国皇家空军让我思考了一下,我做了一些测试。我注意到以下错误:

PSMessageDetails      :
OriginInfo            : test-dbc1
Exception             : System.Management.Automation.Remoting.PSRemotingTransportException: Processing data from remote
                         server failed with the following error message: The client cannot connect to the destination s
                        pecified in the request. Verify that the service on the destination is running and is accepting
                         requests. Consult the logs and documentation for the WS-Management service running on the dest
                        ination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following
                         command on the destination to analyze and configure the WinRM service: "winrm quickconfig". Fo
                        r more information, see the about_Remote_Troubleshooting Help topic.
TargetObject          : System.Management.Automation.PSInvokeExpressionSyncJob
CategoryInfo          : OperationStopped: (System.Manageme...pressionSyncJob:PSInvokeExpressionSyncJob) [], PSRemotingTransportException
FullyQualifiedErrorId : JobFailure
ErrorDetails          :
InvocationInfo        :
PipelineIterationInfo : {}

因此,出于某种原因,它似乎无法使用winRM进行连接,即使挂起脚本并手动运行该脚本不会引发该错误。有人知道为什么在脚本中运行会影响winrm是否可以连接吗?

什么是
$test.test\u arg\u 1
$this.name
?在
$result=@(调用command…
行以查看它们是否设置正确。刚刚测试过,它们设置正确,之后结果肯定为空。使用
Enter-Pssession
cmdlet远程访问目标计算机,逐个执行命令并查看问题所在。尝试运行
get-clustergroup
而不使用任何值以查看问题所在f它返回您期望的结果。我不太确定您使用enter pssession的意思。当我在命令运行后立即进行写调试时,挂起脚本,手动运行完全相同的代码行,它运行良好并返回我正在查找的结果。因此,所编写的命令本身没有任何错误。
enter pssession
invoke command
的功能完全相同,只是您可以实时执行代码,并可能找出错误所在。
Name             : ConsoleHost
Version          : 2.0
InstanceId       : 65fcc12c-4333-49d8-a340-92690d7aeb23
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace
PSMessageDetails      :
OriginInfo            : test-dbc1
Exception             : System.Management.Automation.Remoting.PSRemotingTransportException: Processing data from remote
                         server failed with the following error message: The client cannot connect to the destination s
                        pecified in the request. Verify that the service on the destination is running and is accepting
                         requests. Consult the logs and documentation for the WS-Management service running on the dest
                        ination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following
                         command on the destination to analyze and configure the WinRM service: "winrm quickconfig". Fo
                        r more information, see the about_Remote_Troubleshooting Help topic.
TargetObject          : System.Management.Automation.PSInvokeExpressionSyncJob
CategoryInfo          : OperationStopped: (System.Manageme...pressionSyncJob:PSInvokeExpressionSyncJob) [], PSRemotingTransportException
FullyQualifiedErrorId : JobFailure
ErrorDetails          :
InvocationInfo        :
PipelineIterationInfo : {}