Powershell-Powershell远程会话中的事件转发-不一致的行为

问题描述

我注意到PowerShell ISE和PowerShell控制台之间的行为略有不一致。我正在尝试运行以下脚本,该脚本试图显示主机上远程PowerShell会话中转发的事件数据。从ISE运行时,它可以按预期工作,但是当我从PowerShell控制台运行时,不会显示转发的消息。但是,当我按下“ Tab”键时,突然所有排队的消息立即出现。

我已经在Windows Server 2008 R2和更高版本的操作系统上注意到此行为。我正在使用PowerShell 5.1。

有什么想法吗?谢谢。

Register-EngineEvent -SourceIdentifier RemoteEventOccured -MessageData 'RemoteEventOccured' -Action {
    Write-Host $event.MessageData
} | Out-Null

$RemoteJob = Invoke-Command -ComputerName localhost -AsJob -JobName MyRemoteJob -ScriptBlock {

    Register-EngineEvent -SourceIdentifier RemoteEventOccured  -Forward | Out-Null

    while($true){
        New-Event -SourceIdentifier 'RemoteEventOccured' -MessageData "$(Get-Date): Remote data received..." | Out-Null
        Start-Sleep -Seconds 5
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)