【问题标题】:Powershell EventsPowershell 事件
【发布时间】:2014-03-08 14:54:37
【问题描述】:

如何在powershell中获取$Event的内容

这是我的代码

Add-Type -Path "D:\agsXMPP.dll"

$xmpp = New-Object "agsXMPP.XmppClientConnection"
$xmpp.Username = "fbusername"
$xmpp.Password = "fbpassword"
$xmpp.Server = "chat.facebook.com"


Register-ObjectEvent -InputObject $xmpp -EventName OnXmppConnectionStateChanged -Action {
    Write-Host $Event
}

$xmpp.Open();

这只会输出 System.Management.Automation.PSEventArgs

那个$Event,我期待XmppConnectionState

【问题讨论】:

    标签: powershell powershell-2.0 powershell-3.0 agsxmpp


    【解决方案1】:

    $EventSubscriber:包含一个表示事件订阅者的 PSEventSubscriber 对象。

    $Event:包含一个 PSEventArgs 对象。该值与 CmdLet Get-Event 返回的对象相同。所以你可以尝试使用属性为$Event.TimeGenerated

    $EventArgs :包含表示事件参数的对象,您可以在 Get-Event 返回的属性 SourceArgs 中找到该对象。

    $Sender :包含生成此事件的对象,您可以在 Get-Event 返回的属性 Sender 中找到该对象。

    也许您正在寻找$EventArgs?不要忘记使用| get-member 来检索不同变量的内容。

    【讨论】:

      猜你喜欢
      • 2022-12-18
      • 2011-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-17
      相关资源
      最近更新 更多